text:
/*-----------------------------------------------------------------------------+
Copyright (c) 2008-2009: Joachim Faulhaber
+------------------------------------------------------------------------------+
   Distributed under the Boost Software License, Version 1.0.
      (See accompanying file LICENCE.txt or copy at
           http://www.boost.org/LICENSE_1_0.txt)
+-----------------------------------------------------------------------------*/
#define BOOST_TEST_MODULE icl::misc unit test

#define BOOST_ICL_TEST_CHRONO

#include <libs/icl/test/disable_test_warnings.hpp>
#include <string>
#include <vector>
#include <boost/mpl/list.hpp>
#include "../unit_test_unwarned.hpp"
#include <boost/test/test_case_template.hpp>

// interval instance types
#include "../test_type_lists.hpp"
#include "../test_value_maker.hpp"

#include <boost/type_traits/is_same.hpp>
#include <boost/icl/rational.hpp>

#include <boost/icl/detail/interval_morphism.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/icl/split_interval_set.hpp>
#include "../test_laws.hpp"

using namespace std;
using namespace boost;
using namespace unit_test;
using namespace boost::icl;

BOOST_AUTO_TEST_CASE(test_law_complementarity)
{
    //LAW Inner complementarity: x + between(x) == hull(x)
    //LAW: length(x) + length(between(x)) = length(hull(x))
    typedef interval_map<rational<int>, int> RatioMapT;
    typedef interval_set<rational<int> > RatioSetT;
    typedef RatioSetT::interval_type     IntervalT;
    typedef RatioSetT::element_type      RatT;
    typedef RatioSetT::difference_type   DiffT;

    RatioSetT set_a;
    (((set_a += IntervalT(RatT(0),   RatT(1)  ) )
             -= IntervalT(RatT(1,9), RatT(2,9))  )
             -= IntervalT(RatT(3,9), RatT(4,9))   )
             -= IntervalT(RatT(5,9), RatT(6,9));

    RatioSetT between_a  = RatioSetT(hull(set_a)) - set_a;
    RatioSetT between_a2;
    between(between_a2, set_a);
    BOOST_CHECK_EQUAL( between_a, between_a2 );

    DiffT len_set_a     = length(set_a);
    DiffT len_between_a = length(between_a);

    //cout << set_a     << " length= " << len_set_a     << endl;
    //cout << between_a << " length= " << len_between_a << endl;

    RatioSetT span_a = set_a + between_a;
    RatioSetT hull_a = RatioSetT(hull(set_a));
    //cout << span_a << endl;

    BOOST_CHECK_EQUAL( span_a, hull_a );
    BOOST_CHECK_EQUAL( len_set_a + len_between_a, length(hull_a) );

    BOOST_CHECK((has_inner_complementarity<RatioSetT,RatioSetT>(set_a)));
    BOOST_CHECK((has_length_complementarity(set_a)));
    BOOST_CHECK((has_length_as_distance<RatioSetT,RatioSetT>(set_a)));
}

BOOST_AUTO_TEST_CASE(test_between)
{
    //LAW: between(a,b) == between(b,a);
    typedef int T;
    typedef interval<T>::type IntervalT;
    typedef interval_set<T>   IntervalSetT;

    IntervalT itv_a = I_D(1,3);
    IntervalT itv_b = I_D(5,7);

    IntervalT beween_a_b = between(itv_a, itv_b);
    IntervalT beween_b_a = between(itv_b, itv_a);

    //cout << beween_a_b << endl;
    //cout << beween_b_a << endl;
    BOOST_CHECK_EQUAL( beween_a_b, beween_b_a );
}

BOOST_AUTO_TEST_CASE(element_iteration)
{
    interval_map<int,int> map_a;
    map_a += make_pair(interval<int>::right_open(0,3),1);
    //cout << map_a << endl;

    //for(interval_map<int,int>::element_iterator elem = elements_begin(map_a);
    //    elem != elements_end(map_a); elem++)
    //    cout << "(" << elem->first << "," << elem->second << ")";
    //cout << "\n-------------------------------------\n";

    std::pair<const int, int> search_pair(2,1);

    //interval_map<int,int>::element_const_iterator found
    interval_map<int,int>::element_iterator found
        = std::find(elements_begin(map_a), elements_end(map_a), search_pair);
    // cout << "(" << found->first << "," << found->second << ")\n";
    BOOST_CHECK_EQUAL( found->first,  2 );
    BOOST_CHECK_EQUAL( found->second, 1 );

    // Assignment of an associated value via element_iterator
    const_cast<int&>(found->second) = 2;
    // cout << map_a << endl;
    BOOST_CHECK_EQUAL( map_a.begin()->second, 2 );
}

BOOST_AUTO_TEST_CASE(test_interval_bounds_1)
{
    BOOST_CHECK_EQUAL(left_bracket(interval_bounds::closed()),      "[");
    BOOST_CHECK_EQUAL(left_bracket(interval_bounds::right_open()),  "[");
    BOOST_CHECK_EQUAL(left_bracket(interval_bounds::left_open()),   "(");
    BOOST_CHECK_EQUAL(left_bracket(interval_bounds::open()),        "(");
    BOOST_CHECK_EQUAL(right_bracket(interval_bounds::closed()),     "]");
    BOOST_CHECK_EQUAL(right_bracket(interval_bounds::right_open()), ")");
    BOOST_CHECK_EQUAL(right_bracket(interval_bounds::left_open()),  "]");
    BOOST_CHECK_EQUAL(right_bracket(interval_bounds::open()),       ")");

    continuous_interval<double> a_1 = continuous_interval<double>(-5.0, -2.3, interval_bounds::closed());
    continuous_interval<double> b_1 = continuous_interval<double>(-2.6, 4.0, interval_bounds::closed());

    split_interval_set<double> a, b, a_o_b, b_o_a;
    a_o_b += a_1;
    a_o_b += b_1;

    b_o_a += b_1;
    b_o_a += a_1;

    BOOST_CHECK_EQUAL(a_o_b, b_o_a);

    continuous_interval<double> c_1 = continuous_interval<double>(1.0, 3.0, interval_bounds::closed());
    continuous_interval<double> b_2 = right_subtract(b_1, c_1);

    BOOST_CHECK_EQUAL(b_2.bounds(), interval_bounds::right_open());
    BOOST_CHECK_EQUAL(icl::bounds(b_2), interval_bounds::right_open());

    continuous_interval<double> L0T = continuous_interval<double>(0.0, 0.0, interval_bounds::closed());
    continuous_interval<double> C0T = continuous_interval<double>(0.0, 0.0, interval_bounds::left_open());
    continuous_interval<double> L0D = continuous_interval<double>(0.0, 0.0, interval_bounds::right_open());
    continuous_interval<double> C0D = continuous_interval<double>(0.0, 0.0, interval_bounds::open());

    BOOST_CHECK_EQUAL(icl::is_empty(L0T), false);
    BOOST_CHECK_EQUAL(icl::is_empty(C0T), true);
    BOOST_CHECK_EQUAL(icl::is_empty(L0D), true);
    BOOST_CHECK_EQUAL(icl::is_empty(C0D), true);

    continuous_interval<double> L0_1T = continuous_interval<double>(0.0, 1.0, interval_bounds::closed());
    continuous_interval<double> L1_2T = continuous_interval<double>(1.0, 2.0, interval_bounds::closed());
    BOOST_CHECK_EQUAL(icl::exclusive_less(L0_1T, L1_2T), false);
    BOOST_CHECK_EQUAL(icl::inner_bounds(L0_1T, L1_2T) == interval_bounds::open(), true);

    continuous_interval<double> L0_1D = continuous_interval<double>(0.0, 1.0, interval_bounds::right_open());
    BOOST_CHECK_EQUAL(icl::exclusive_less(L0_1D, L1_2T), true);
    BOOST_CHECK_EQUAL(icl::inner_bounds(L0_1D, L1_2T) == interval_bounds::right_open(), true);

    continuous_interval<double> C1_2T = continuous_interval<double>(1.0, 2.0, interval_bounds::left_open());
    BOOST_CHECK_EQUAL(icl::exclusive_less(L0_1T, C1_2T), true);
    BOOST_CHECK_EQUAL(icl::inner_bounds(L0_1T, C1_2T) == interval_bounds::left_open(), true);

    BOOST_CHECK_EQUAL(icl::exclusive_less(L0_1D, C1_2T), true);
    BOOST_CHECK_EQUAL(icl::inner_bounds(L0_1D, C1_2T) == interval_bounds::closed(), true);

    BOOST_CHECK_EQUAL(static_cast<int>(icl::right(L0_1T.bounds()).bits()), 1);
    BOOST_CHECK_EQUAL(static_cast<int>(icl::right(L0_1D.bounds()).bits()), 0);

    BOOST_CHECK_EQUAL(icl::right_bounds(L0_1D, L0_1T), interval_bounds::left_open());
}

BOOST_AUTO_TEST_CASE(test_infinities)
{
    BOOST_CHECK(( has_std_infinity<double>::value));
    BOOST_CHECK((!has_std_infinity<int>::value));

    BOOST_CHECK(( has_max_infinity<int>::value ));
    BOOST_CHECK((!has_max_infinity<double>::value ));

    //--------------------------------------------------------------------------
    BOOST_CHECK_EQUAL( numeric_infinity<double>::value(),  (std::numeric_limits<double>::infinity)() );
    BOOST_CHECK_EQUAL( numeric_infinity<int>::value(),     (std::numeric_limits<int>::max)() );
    BOOST_CHECK_EQUAL( numeric_infinity<std::string>::value(), std::string() );

    //--------------------------------------------------------------------------
    BOOST_CHECK_EQUAL( infinity<double>::value(),  (std::numeric_limits<double>::infinity)() );
    BOOST_CHECK_EQUAL( infinity<int>::value(),     (std::numeric_limits<int>::max)() );
    BOOST_CHECK_EQUAL( infinity<std::string>::value(), identity_element<std::string>::value() );

    //--------------------------------------------------------------------------
    BOOST_CHECK_EQUAL( infinity<chrono::duration<double> >::value()
                     , chrono::duration<double>((std::numeric_limits<double>::infinity)()) );
    BOOST_CHECK_EQUAL( infinity<chrono::duration<int> >::value()
                     , chrono::duration<int>((std::numeric_limits<int>::max)()) );
}

BOOST_AUTO_TEST_CASE(test_difference_types)
{
    BOOST_CHECK(( boost::is_same< int,            difference_type_of<int>::type >::value ));
    BOOST_CHECK(( boost::is_same< double,         difference_type_of<double>::type >::value ));
    BOOST_CHECK(( boost::is_same< std::ptrdiff_t, difference_type_of<int*>::type >::value ));

    BOOST_CHECK(( has_difference_type<std::string>::value ));
    BOOST_CHECK(( boost::is_same< std::string::difference_type, difference_type_of<std::string>::type >::value ));
    BOOST_CHECK(( boost::is_same< std::ptrdiff_t, difference_type_of<std::string>::type >::value ));

    BOOST_CHECK((  boost::is_same<                    chrono::duration<int>
                                 , difference_type_of<chrono::duration<int> >::type >::value ));
    BOOST_CHECK((  boost::is_same<                    chrono::duration<double>
                                 , difference_type_of<chrono::duration<double> >::type >::value ));

    BOOST_CHECK((  boost::is_same<                    Now::time_point::duration
                                 , difference_type_of<Now::time_point>::type >::value ));

    typedef boost::chrono::time_point<Now, boost::chrono::duration<double> > contin_timeT;
    BOOST_CHECK((  boost::is_same<                    contin_timeT::duration
                                 , difference_type_of<contin_timeT>::type >::value ));

    typedef boost::chrono::time_point<Now, boost::chrono::duration<int> > discr_timeT;
    BOOST_CHECK((  boost::is_same<                    chrono::duration<int>
                                 , difference_type_of<discr_timeT>::type >::value ));
}

BOOST_AUTO_TEST_CASE(test_size_types)
{
    BOOST_CHECK(( boost::is_same< std::size_t,    size_type_of<int>::type >::value ));
    BOOST_CHECK(( boost::is_same< std::size_t,    size_type_of<double>::type >::value ));
    BOOST_CHECK(( boost::is_same< std::size_t,    size_type_of<int*>::type >::value ));
    BOOST_CHECK(( boost::is_same< std::size_t,    size_type_of<std::string>::type >::value ));
    BOOST_CHECK(( boost::is_same<              chrono::duration<int>
                                , size_type_of<chrono::duration<int> >::type >::value ));
    BOOST_CHECK(( boost::is_same<              chrono::duration<double>
                                , size_type_of<chrono::duration<double> >::type >::value ));

    typedef boost::chrono::time_point<Now, boost::chrono::duration<int> > discr_timeT;
    BOOST_CHECK((  boost::is_same< chrono::duration<int>
                                 , size_type_of<discr_timeT>::type >::value ));

    typedef boost::chrono::time_point<Now, boost::chrono::duration<double> > contin_timeT;
    BOOST_CHECK((  boost::is_same< contin_timeT::duration
                                 , size_type_of<contin_timeT>::type >::value ));
}

BOOST_AUTO_TEST_CASE(test_chrono_identity_elements)
{
    chrono::duration<int> idel_i = icl::identity_element<chrono::duration<int> >::value();
    //cout << "dur<int>0 = " << idel_i << endl;
    chrono::duration<double> idel_d = icl::identity_element<chrono::duration<int> >::value();
    //cout << "dur<dbl>0 = " << idel_d << endl;

    BOOST_CHECK(( boost::is_same<              chrono::duration<int>
                                , size_type_of<chrono::duration<int> >::type >::value ));
}


text:
/*
 * MIT License
 *
 * Copyright (c) 2015 Alexis LE GOADEC
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

/*
 * Modélisation de la matrice d'adjacence associée à l'hypergraphe.
 *
 */

#ifndef MODEL_INCLUDE_ADJACENTMATRIX_HH_
#define MODEL_INCLUDE_ADJACENTMATRIX_HH_

#include "LibType.hh"
#include <boost/tuple/tuple.hpp>

class HyperEdge;

class HyperVertex;

/**
 * Déclaration de la matrice d'adjacence.
 */
class AdjacentMatrix {

public:

	/**
	 * Constructeur par défaut.
	 */
	AdjacentMatrix();

	/**
	 * Constructeur de taille particulière.
	 * @param x L'abscisse
	 * @param y L'ordonnée de la matrice.
	 */
	AdjacentMatrix(const unsigned int&, const unsigned int&);

	/**
	 * Modification de la taille de la matrice.
	 * @param x L'abscisse
	 * @param y L'ordonnée de la matrice.
	 */
	void resize(const unsigned int&, const unsigned int&);

	/**
	 * Ajouter un hyper-vertex à la matrice.
	 * @param HyperVertex L'hyper-vertex à ajouter.
	 */
	void addHyperVertex(const boost::shared_ptr<HyperVertex>&);

	/**
	 * Ajouter une hyper-arête à la matrice.
	 * @param HyperEdge L'hyper-arête à ajouter.
	 */
	void addHyperEdge(const boost::shared_ptr<HyperEdge>&);

	/**
	 * Vérifier si l'hyper-vertex est dans l'hyper-arête.
	 * @param L'hyper-vertex à vérifier.
	 * @param L'hyper-arête dont la précence de l'hyper-vertex est à vérifier.
	 * @return True si l'hyper-vertex est dans l'hyper-arête, False sinon.
	 */
	bool isVertexInEdge(const boost::shared_ptr<HyperVertex>&, const boost::shared_ptr<HyperEdge>&) const;

	/**
	 * Vérifier si une hyper-arête est dans la liste des hyper-arêtes d'un hyper-vertex.
	 * @param L'hyper-arête à vérifier.
	 * @param L'hyper-vertex.
	 * @return True si l'hyper-vertex contient l'hyper-arête dans sa liste, False sinon.
	 */
	bool isEdgeInVertex(const boost::shared_ptr<HyperEdge>&, const boost::shared_ptr<HyperVertex>&) const;

	/**
	 * Vérifier si l'hyper-vertex ayant l'identifiant i se trouve dans l'hyper-arête ayant l'identifiant j.
	 * @param L'identifiant de l'hyper-vertex.
	 * @param L'identifiant de l'hyper-arête.
	 * @return True si c'est le cas, False sinon.
	 */
	bool isVertexInEdge(const int&, const int&) const;

	/**
	 * Vérifier si l'hyper-arête ayant l'identifiant i se trouve dans la liste de l'hyper-vertex ayant l'identifiant j.
	 * @param L'identifiant de l'hyper-arête.
	 * @param L'identifiant de l'hyper-vertex.
	 * @return True si c'est le cas, False sinon.
	 */
	bool isEdgeInVertex(const int&, const int&) const;

	/**
	 * Obtenir la matrice d'adjacence booléenne.
	 * @return La matrice d'adjacence booléenne.
	 */
	LibType::AdjacentMatrixContainerBool& getBoolAdjacentMatrix();

	/**
	 * Obtenir la matrice d'adjacence entière.
	 * @return La matrice d'adjacence entière.
	 */
	LibType::AdjacentMatrixContainerInt& getUIntAdjacentMatrix();

	/**
	 * Obtenir le degré d'un hyper-vertex.
	 * @param L'hyper-vertex dont on souhaite obtenir le degré.
	 * @return Nn entier positif correspondant au degrès de l'hyper-vertex.
	 */
	unsigned int getVertexDegree(const boost::shared_ptr<HyperVertex>&) const;

	/**
	 * Obtenir l'effectif d'une hyper-arête.
	 * @param L'hyper-arête dont on souhaite obtenir l'effectif.
	 * @return Un entier positif correspondant au nombre d'hyper-vertex dans l'hyper-arête.
	 */
	unsigned int getEdgeSize(const boost::shared_ptr<HyperEdge>&) const;

	/**
	 * Obtenir le co-rang de l'hypergraphe.
	 * @return Un entie correspondant au co-rang.
	 */
	unsigned int getCoRank() const;

	/**
	 * Obtenir le rang de l'hypergraphe.
	 * @return Un entie correspondant au rang.
	 */
	unsigned int getRank() const;

	/**
	 * Obtenir les dimensions de la matrice d'adjacence.
	 * @return Un tuple dont le premier nombre est l'abscisse, le second est l'ordonnée.
	 */
	boost::tuple<unsigned int, unsigned int>&
	getMatrixDimension();

	/**
	 * Fonction-test affichant la matrice sur la sortie standard - NE PAS UTILISER.
	 */
	void display() const;

protected:

	/**
	 * L'abscisse.
	 */
	unsigned int _m;

	/**
	 * L'ordonnée.
	 */
	unsigned int _n;

	/**
	 * Les données de la matrice d'adjacence booléenne.
	 */
	LibType::AdjacentMatrixContainerBool _adjacentMatrixBool;

	/**
	 * Les données de la matrice d'adjacence entière.
	 */
	LibType::AdjacentMatrixContainerInt  _adjacentMatrixUInt;

};

#endif

ext: hh

max_stars_repo_name: ehzawad/HyperGraphLib

max_issues_repo_name: ehzawad/HyperGraphLib

max_forks_repo_name: ehzawad/HyperGraphLib


text:
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009. 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)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
//[doc_ipc_message
#include <boost/interprocess/managed_shared_memory.hpp>
#include <cstdlib> //std::system
#include <sstream>
//<-
#include "../test/get_process_id_name.hpp"
//->

int main (int argc, char *argv[])
{
   using namespace boost::interprocess;
   if(argc == 1){  //Parent process
      //Remove shared memory on construction and destruction
      struct shm_remove
      {
      //<-
      #if 1
         shm_remove() {  shared_memory_object::remove(test::get_process_id_name()); }
         ~shm_remove(){  shared_memory_object::remove(test::get_process_id_name()); }
      #else
      //->
         shm_remove() {  shared_memory_object::remove("MySharedMemory"); }
         ~shm_remove(){  shared_memory_object::remove("MySharedMemory"); }
      //<-
      #endif
      //->
      } remover;

      //Create a managed shared memory segment
      //<-
      #if 1
      managed_shared_memory segment(create_only, test::get_process_id_name(), 65536);
      #else
      //->
      managed_shared_memory segment(create_only, "MySharedMemory", 65536);
      //<-
      #endif
      //->

      //Allocate a portion of the segment (raw memory)
      std::size_t free_memory = segment.get_free_memory();
      void * shptr = segment.allocate(1024/*bytes to allocate*/);

      //Check invariant
      if(free_memory <= segment.get_free_memory())
         return 1;

      //An handle from the base address can identify any byte of the shared
      //memory segment even if it is mapped in different base addresses
      managed_shared_memory::handle_t handle = segment.get_handle_from_address(shptr);
      std::stringstream s;
      s << argv[0] << " " << handle;
      //<-
      s << " " << test::get_process_id_name();
      //->
      s << std::ends;
      //Launch child process
      if(0 != std::system(s.str().c_str()))
         return 1;
      //Check memory has been freed
      if(free_memory != segment.get_free_memory())
         return 1;
   }
   else{
      //Open managed segment
      //<-
      #if 1
      managed_shared_memory segment(open_only, argv[2]);
      #else
      //->
      managed_shared_memory segment(open_only, "MySharedMemory");
      //<-
      #endif
      //->

      //An handle from the base address can identify any byte of the shared
      //memory segment even if it is mapped in different base addresses
      managed_shared_memory::handle_t handle = 0;

      //Obtain handle value
      std::stringstream s; s << argv[1]; s >> handle;

      //Get buffer local address from handle
      void *msg = segment.get_address_from_handle(handle);

      //Deallocate previously allocated memory
      segment.deallocate(msg);
   }
   return 0;
}
//]
#include <boost/interprocess/detail/config_end.hpp>

ext: cpp

max_issues_repo_name: boost-cmake/vintage

max_forks_repo_name: boost-cmake/vintage


text:
/*
* Copyright (c) by CryptoLab inc.
* This program is licensed under a
* Creative Commons Attribution-NonCommercial 3.0 Unported License.
* You should have received a copy of the license along with this
* work.  If not, see <http://creativecommons.org/licenses/by-nc/3.0/>.
*/
#include "TestScheme.h"

#include <NTL/BasicThreadPool.h>
#include <NTL/ZZ.h>
#include <complex>

#include "Ciphertext.h"
#include "EvaluatorUtils.h"
#include "Ring.h"
#include "Scheme.h"
#include "SchemeAlgo.h"
#include "SecretKey.h"
#include "StringUtils.h"
#include "TimeUtils.h"
#include "SerializationUtils.h"

using namespace std;
using namespace NTL;

//----------------------------------------------------------------------------------
//   STANDARD TESTS
//----------------------------------------------------------------------------------

void TestScheme::testEncrypt(long logq, long logp, long logn) {
	cout << "!!! START TEST ENCRYPT !!!" << endl;
	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	long n = (1 << logn);
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	Ciphertext cipher;

	timeutils.start("Encrypt");
	scheme.encrypt(cipher, mvec, n, logp, logq);
	timeutils.stop("Encrypt");

	timeutils.start("Decrypt");
	complex<double>* dvec = scheme.decrypt(secretKey, cipher);
	timeutils.stop("Decrypt");

	StringUtils::compare(mvec, dvec, n, "val");

	cout << "!!! END TEST ENCRYPT !!!" << endl;
}

void TestScheme::testEncryptSingle(long logq, long logp) {
	cout << "!!! START TEST ENCRYPT SINGLE !!!" << endl;
	srand(time(NULL));
	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	complex<double> mval = EvaluatorUtils::randomComplex();
	Ciphertext cipher;

	timeutils.start("Encrypt Single");
	scheme.encryptSingle(cipher, mval, logp, logq);
	timeutils.stop("Encrypt Single");

	complex<double> dval = scheme.decryptSingle(secretKey, cipher);

	StringUtils::compare(mval, dval, "val");

	cout << "!!! END TEST ENCRYPT SINGLE !!!" << endl;
}

void TestScheme::testAdd(long logq, long logp, long logn) {
	cout << "!!! START TEST ADD !!!" << endl;

	srand(time(NULL));
	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	long n = (1 << logn);
	complex<double>* mvec1 = EvaluatorUtils::randomComplexArray(n);
	complex<double>* mvec2 = EvaluatorUtils::randomComplexArray(n);
	complex<double>* madd = new complex<double>[n];

	for(long i = 0; i < n; i++) {
		madd[i] = mvec1[i] + mvec2[i];
	}

	Ciphertext cipher1, cipher2;
	scheme.encrypt(cipher1, mvec1, n, logp, logq);
	scheme.encrypt(cipher2, mvec2, n, logp, logq);

	timeutils.start("Addition");
	scheme.multAndEqual(cipher1, cipher2);
	timeutils.stop("Addition");

	complex<double>* dadd = scheme.decrypt(secretKey, cipher1);

	//StringUtils::showVec(mvec1, n);
	//StringUtils::showVec(mvec2, n);
	//<StringUtils::showVec(madd, n);

	StringUtils::compare(madd, dadd, n, "add");

	cout << "!!! END TEST ADD !!!" << endl;
}

void TestScheme::testMult(long logq, long logp, long logn) {
	cout << "!!! START TEST MULT !!!" << endl;

	srand(time(NULL));
	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	long n = (1 << logn);
	complex<double>* mvec1 = EvaluatorUtils::randomComplexArray(n);
	complex<double>* mvec2 = EvaluatorUtils::randomComplexArray(n);
	complex<double>* mmult = new complex<double>[n];

	StringUtils::showVec(mvec1, n);
	StringUtils::showVec(mvec2, n);

	for(long i = 0; i < n; i++) {
		mmult[i] = mvec1[i] * mvec2[i];
	}

	Ciphertext cipher1, cipher2;
	scheme.encrypt(cipher1, mvec1, n, logp, logq);
	scheme.encrypt(cipher2, mvec2, n, logp, logq);

	timeutils.start("Multiplication");
	scheme.multAndEqual(cipher1, cipher2);
	timeutils.stop("Multiplication");

	complex<double>* dmult = scheme.decrypt(secretKey, cipher1);

	StringUtils::showVec(mmult, n);

	StringUtils::compare(mmult, dmult, n, "mult");

	cout << "!!! END TEST MULT !!!" << endl;
}

void TestScheme::testimult(long logq, long logp, long logn) {
	cout << "!!! START TEST i MULTIPLICATION !!!" << endl;

	srand(time(NULL));
	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	long n = (1 << logn);

	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	complex<double>* imvec = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		imvec[i].real(-mvec[i].imag());
		imvec[i].imag(mvec[i].real());
	}

	StringUtils::showVec(mvec, n);
	StringUtils::showVec(imvec, n);

	Ciphertext cipher;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start("Multiplication by i");
	scheme.imultAndEqual(cipher);
	timeutils.stop("Multiplication by i");

	complex<double>* idvec = scheme.decrypt(secretKey, cipher);

	StringUtils::compare(imvec, idvec, n, "imult");

	cout << "!!! END TEST i MULTIPLICATION !!!" << endl;
}

//----------------------------------------------------------------------------------
//   ROTATE & CONJUGATE
//----------------------------------------------------------------------------------

void TestScheme::testRotateFast(long logq, long logp, long logn, long logr) {
	cout << "!!! START TEST ROTATE FAST !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	long n = (1 << logn);
	long r = (1 << logr);
	scheme.addLeftRotKey(secretKey, r);
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	Ciphertext cipher;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start("Left Rotate Fast");
	scheme.leftRotateFastAndEqual(cipher, r);
	timeutils.stop("Left Rotate Fast");

	complex<double>* dvec = scheme.decrypt(secretKey, cipher);

	StringUtils::showVec(mvec, n);

	EvaluatorUtils::leftRotateAndEqual(mvec, n, r);

	StringUtils::showVec(mvec, n);
	//StringUtils::showVec(mvec, n);
	//StringUtils::showVec(dvec, n);
	StringUtils::compare(mvec, dvec, n, "rot");

	cout << "!!! END TEST ROTATE BY POWER OF 2 BATCH !!!" << endl;
}

void TestScheme::testConjugate(long logq, long logp, long logn) {
	cout << "!!! START TEST CONJUGATE !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	scheme.addConjKey(secretKey);

	long n = (1 << logn);

	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	complex<double>* mvecconj = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mvecconj[i] = conj(mvec[i]);
	}

	Ciphertext cipher;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start("Conjugate");
	scheme.conjugateAndEqual(cipher);
	timeutils.stop("Conjugate");

	complex<double>* dvecconj = scheme.decrypt(secretKey, cipher);
	StringUtils::showVec(mvec, n);
	StringUtils::showVec(mvecconj, n);
	StringUtils::compare(mvecconj, dvecconj, n, "conj");

	cout << "!!! END TEST CONJUGATE !!!" << endl;
}

//----------------------------------------------------------------------------------
//   POWER & PRODUCT TESTS
//----------------------------------------------------------------------------------

void TestScheme::testPowerOf2(long logq, long logp, long logn, long logdeg) {
	cout << "!!! START TEST POWER OF 2 !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	long degree = 1 << logdeg;
	complex<double>* mvec = new complex<double>[n];
	//cout << "mvec and mpow 2^" << logdeg << endl;
	complex<double>* mpow = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mvec[i] = EvaluatorUtils::randomCircle();
		mpow[i] = pow(mvec[i], degree);
	}
	//StringUtils::showVec(mvec, n);
	//StringUtils::showVec(mpow, n);

	Ciphertext cipher, cpow;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start("Power of 2");
	algo.powerOf2(cpow, cipher, logp, logdeg);
	timeutils.stop("Power of 2");

	complex<double>* dpow = scheme.decrypt(secretKey, cpow);
	StringUtils::compare(mpow, dpow, n, "pow2");

	cout << "!!! END TEST POWER OF 2 !!!" << endl;
}

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

void TestScheme::testPower(long logq, long logp, long logn, long degree) {
	cout << "!!! START TEST POWER !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomCircleArray(n);
	cout << "mvec and mpow ^"<< degree << endl;
	StringUtils::showVec(mvec, n);

	complex<double>* mpow = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mpow[i] = pow(mvec[i], degree);
	}
	StringUtils::showVec(mpow, n);

	Ciphertext cipher, cpow;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start("Power");
	algo.power(cpow, cipher, logp, degree);
	timeutils.stop("Power");

	complex<double>* dpow = scheme.decrypt(secretKey, cpow);
	StringUtils::compare(mpow, dpow, n, "pow");

	cout << "!!! END TEST POWER !!!" << endl;
}

//----------------------------------------------------------------------------------
//   FUNCTION TESTS
//----------------------------------------------------------------------------------

void TestScheme::testInverse(long logq, long logp, long logn, long steps) {
	cout << "!!! START TEST INVERSE !!!" << endl;

	srand(time(NULL));
	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomCircleArray(n, 0.1);
	//cout << "mvec and minv" << endl;
	//StringUtils::showVec(mvec, n);
	complex<double>* minv = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		minv[i] = 1. / mvec[i];
	}
	//StringUtils::showVec(minv, n);

	Ciphertext cipher, cinv;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start("Inverse");
	algo.inverse(cinv, cipher, logp, steps);
	timeutils.stop("Inverse");

	complex<double>* dinv = scheme.decrypt(secretKey, cinv);
	StringUtils::compare(minv, dinv, n, "inv");

	cout << "!!! END TEST INVERSE !!!" << endl;
}

void TestScheme::testLogarithm(long logq, long logp, long logn, long degree) {
	cout << "!!! START TEST LOGARITHM !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n, 0.1);
	//cout << "mvec and mlog" << endl;
	//StringUtils::showVec(mvec, n);
	complex<double>* mlog = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mlog[i] = log(mvec[i] + 1.);
	}
	//StringUtils::showVec(mlog, n);

	Ciphertext cipher, clog;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start(LOGARITHM);
	algo.function(clog, cipher, LOGARITHM, logp, degree);
	timeutils.stop(LOGARITHM);

	complex<double>* dlog = scheme.decrypt(secretKey, clog);
	StringUtils::compare(mlog, dlog, n, LOGARITHM);

	cout << "!!! END TEST LOGARITHM !!!" << endl;
}

void TestScheme::testExponent(long logq, long logp, long logn, long degree) {
	cout << "!!! START TEST EXPONENT !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	//cout << "mvec and mexp" << endl;
	//StringUtils::showVec(mvec, n);
	complex<double>* mexp = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mexp[i] = exp(mvec[i]);
	}
	//StringUtils::showVec(mexp, n);

	Ciphertext cipher, cexp;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start(EXPONENT);
	algo.function(cexp, cipher, EXPONENT, logp, degree);
	timeutils.stop(EXPONENT);

	complex<double>* dexp = scheme.decrypt(secretKey, cexp);
	StringUtils::compare(mexp, dexp, n, EXPONENT);

	cout << "!!! END TEST EXPONENT !!!" << endl;
}

void TestScheme::testSqrt4(long logq, long logp, long logn) {
	cout << "!!! START TEST SQRT4 !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n, 20); // get a rdm vector in [0, 20]^n
	complex<double>* msqrt = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mvec[i]  = complex<double>(mvec[i].real(), 0);
		msqrt[i] = complex<double>(sqrt(abs(mvec[i].real())), sqrt(abs(mvec[i].imag())));
	}
	StringUtils::showVec(mvec, n);

	Ciphertext cipher, csqrt;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start(SQRT4);
	algo.function(csqrt, cipher, SQRT4, logp, 5);
	timeutils.stop(SQRT4);

	complex<double>* dsqrt = scheme.decrypt(secretKey, csqrt);
	//StringUtils::showVec(dsqrt, n);
	StringUtils::compare(msqrt, dsqrt, n, SQRT4);

	cout << "!!! END TEST SQRT4 !!!" << endl;
}

void TestScheme::testSqrt8(long logq, long logp, long logn) {
	cout << "!!! START TEST SQRT8 !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n, 12); // get a rdm vector in [0, 12]^n
	complex<double>* msqrt = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mvec[i]  = complex<double>(mvec[i].real(), 0.);
		msqrt[i] = complex<double>(sqrt(abs(mvec[i].real())), sqrt(abs(mvec[i].imag())));
	}

	Ciphertext cipher, csqrt;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start(SQRT8);
	algo.function(csqrt, cipher, SQRT8, logp, 9);
	timeutils.stop(SQRT8);

	complex<double>* dsqrt = scheme.decrypt(secretKey, csqrt);
	StringUtils::compare(msqrt, dsqrt, n, SQRT8);

	cout << "!!! END TEST SQRT8 !!!" << endl;
}

void TestScheme::testAllSqrt(long logq, long logp, long logn) {
	cout << "!!! START TEST SQRT8 !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n, 10); // get a rdm vector in [0, 12]^n
	complex<double>* msqrt = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mvec[i]  = complex<double>(mvec[i].real(), 0.);
		msqrt[i] = complex<double>(sqrt(abs(mvec[i].real())), sqrt(abs(mvec[i].imag())));
	}

	Ciphertext cipher, csqrt, csqrt2;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start(SQRT8);
	algo.function(csqrt, cipher, SQRT8, logp, 9);
	timeutils.stop(SQRT8);

	timeutils.start(SQRT8);
	Ciphertext cipher2;

	scheme.square(cipher2, cipher);
	//cout << "c2_logQ = "<<cipher2.logq << endl;

	scheme.reScaleByAndEqual(cipher2, logp); // cipher2.logq : logq - logp
	//cout << "c2_logQ = "<<cipher2.logq << endl;

	Ciphertext cipher4;
	scheme.square(cipher4, cipher2);
	//cout << "c4_logQ = "<<cipher4.logq << endl;
	scheme.reScaleByAndEqual(cipher4, logp); // cipher4.logq : logq -2logp
	//cout << "c4_logQ = "<<cipher4.logq << endl;

	Ciphertext cipher8;
	scheme.square(cipher8, cipher4);
	//cout << "c8_logQ = "<<cipher8.logq << endl;
	scheme.reScaleByAndEqual(cipher8, logp); // cipher4.logq : logq -2logp
	//cout << "c8_logQ = "<<cipher8.logq << endl;

	RR c;
	c =  45./144; //a0/a1
	Ciphertext cipher01;
	scheme.addConst(cipher01, cipher, c, logp);
	//cout << "cip1_logQ = "<<cipher01.logq << endl;

	c = 288./323; //a1
	scheme.multByConstAndEqual(cipher01, c, logp);
	//cout << "cip1_logQ = "<<cipher01.logq << endl;
	scheme.reScaleByAndEqual(cipher01, logp);
	//cout << "cip1_logQ = "<<cipher01.logq << endl;

	c = -125./24; //a2/a3
	Ciphertext cipher23;
	scheme.addConst(cipher23, cipher, c, logp);
	//cout << "cip23_logQ = "<<cipher23.logq << endl;

	c = 44352./1009375;//a3
	scheme.multByConstAndEqual(cipher23, c, logp);
	//cout << "cip23_logQ = "<<cipher23.logq << endl;
	scheme.reScaleByAndEqual(cipher23, logp);
	//cout << "cip23_logQ = "<<cipher23.logq << endl;

	scheme.multAndEqual(cipher23, cipher2);
	//cout << "cip23_logQ = "<<cipher23.logq << endl;
	scheme.reScaleByAndEqual(cipher23, logp);
	//cout << "cip23_logQ = "<<cipher23.logq << endl;

	scheme.addAndEqual(cipher23, cipher01);
	//cout << "cip23_logQ = "<<cipher23.logq << endl;

	c = -5625./392; //a4/a5
	Ciphertext cipher45;
	scheme.addConst(cipher45, cipher, c, logp);
	//cout << "cip45_logQ = "<<cipher45.logq << endl;

	c = 224224./630859375; //a5
	scheme.multByConstAndEqual(cipher45, c, logp);
	//cout << "cip45_logQ = "<<cipher45.logq << endl;
	scheme.reScaleByAndEqual(cipher45, logp);
	//cout << "cip45_logQ = "<<cipher45.logq << endl;

	c = -15925./352; // a6/a7
	scheme.addConstAndEqual(cipher, c, logp);
	//cout << "cip_logQ = "<<cipher.logq << endl;

	c = 25344./78857421875; // a7
	scheme.multByConstAndEqual(cipher, c, logp);
	//cout << "cip_logQ = "<<cipher.logq << endl;
	scheme.reScaleByAndEqual(cipher, logp);
	//cout << "cip_logQ = "<<cipher.logq << endl;

	scheme.multAndEqual(cipher, cipher2);
	//cout << "cip_logQ = "<<cipher.logq << endl;
	scheme.reScaleByAndEqual(cipher, logp);
	//cout << "cip_logQ = "<<cipher.logq << endl;

	scheme.modDownByAndEqual(cipher45, logp);
	//cout << "cip_logQ = "<<cipher.logq << endl;
	scheme.addAndEqual(cipher, cipher45);
	//cout << "cip_logQ = "<<cipher.logq << endl;

	scheme.multAndEqual(cipher, cipher4);
	//cout << "cip_logQ = "<<cipher.logq << endl;
	scheme.reScaleByAndEqual(cipher, logp);
	//cout << "cip_logQ = "<<cipher.logq << endl;

	scheme.modDownByAndEqual(cipher23, logp);
	scheme.addAndEqual(cipher, cipher23);
	//cout << "cip_logQ = "<<cipher.logq << endl;

	c = -1716./579833984375; //a8
	scheme.multByConstAndEqual(cipher8, c, logp);
	scheme.reScaleByAndEqual(cipher8, logp);
	scheme.addAndEqual(cipher, cipher8);
	timeutils.stop(SQRT8);

	complex<double>* dsqrt = scheme.decrypt(secretKey, csqrt);
	complex<double>* dsqrt2 = scheme.decrypt(secretKey, cipher);
	StringUtils::compare(msqrt, dsqrt, n, SQRT8);
	cout<<" "<<endl;
	StringUtils::compare(msqrt, dsqrt2, n, SQRT8);

	cout << "!!! END TEST SQRT8 !!!" << endl;
}

void TestScheme::testExponentLazy(long logq, long logp, long logn, long degree) {
	cout << "!!! START TEST EXPONENT LAZY !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	//cout << "mvec and mexp" << endl;
	//StringUtils::showVec(mvec, n);
	complex<double>* mexp = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		mexp[i] = exp(mvec[i]);
	}
	//StringUtils::showVec(mexp, n);

	Ciphertext cipher, cexp;
	scheme.encrypt(cipher, mvec, n, logp, logQ);

	timeutils.start(EXPONENT + " lazy");
	algo.functionLazy(cexp, cipher, EXPONENT, logp, degree);
	timeutils.stop(EXPONENT + " lazy");

	complex<double>* dexp = scheme.decrypt(secretKey, cexp);
	StringUtils::compare(mexp, dexp, n, EXPONENT);

	cout << "!!! END TEST EXPONENT LAZY !!!" << endl;
}

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

void TestScheme::testSigmoid(long logq, long logp, long logn, long degree) {
	cout << "!!! START TEST SIGMOID !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;

	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	//cout << "mvec and msig" << endl;
	//StringUtils::showVec(mvec, n);
	complex<double>* msig = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		msig[i] = exp(mvec[i]) / (1. + exp(mvec[i]));
	}
	//StringUtils::showVec(msig, n);

	Ciphertext cipher, csig;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start(SIGMOID);
	algo.function(csig, cipher, SIGMOID, logp, degree);
	timeutils.stop(SIGMOID);

	complex<double>* dsig = scheme.decrypt(secretKey, csig);
	StringUtils::compare(msig, dsig, n, SIGMOID);

	cout << "!!! END TEST SIGMOID !!!" << endl;
}

void TestScheme::testSigmoidLazy(long logq, long logp, long logn, long degree) {
	cout << "!!! START TEST SIGMOID LAZY !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = 1 << logn;
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(n);
	//cout << "mvec and msig" << endl;
	//StringUtils::showVec(mvec, n);
	complex<double>* msig = new complex<double>[n];
	for (long i = 0; i < n; ++i) {
		msig[i] = exp(mvec[i]) / (1. + exp(mvec[i]));
	}
	//StringUtils::showVec(msig, n);

	Ciphertext cipher, csig;
	scheme.encrypt(cipher, mvec, n, logp, logq);

	timeutils.start(SIGMOID + " lazy");
	algo.functionLazy(csig, cipher, SIGMOID, logp, degree);
	timeutils.stop(SIGMOID + " lazy");

	complex<double>* dsig = scheme.decrypt(secretKey, csig);
	StringUtils::compare(msig, dsig, n, SIGMOID);

	cout << "!!! END TEST SIGMOID LAZY !!!" << endl;
}

void TestScheme::testDistance(long logq, long logp, long logn, complex<double>* mvec, complex<double>* mbin, complex<double>* mDes, int points, int norm, double realDistance) {
	cout << "!!! START DISTANCE !!!" << endl;
	srand(time(NULL));
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);
	SchemeAlgo algo(scheme);

	long n = (1 << logn);
	long r = (1 << 0);
	scheme.addLeftRotKey(secretKey, r);
	long r2 = n/2;
	scheme.addLeftRotKey(secretKey, r2);

	timeutils.start(ENC);
	//* Encrypt the plaintext
	Ciphertext cipher;
	scheme.encrypt(cipher, mvec, n, logp, logq);
	timeutils.stop(ENC);

	timeutils.start(DISTANCE);
	//* Create the difference vector
	Ciphertext diff;
	scheme.leftRotateFast(diff, cipher, r);
	scheme.subAndEqual(cipher, diff);

	//* Distroy elements in slot point and n/2+point
	Ciphertext cbin;
	scheme.encrypt(cbin, mbin, n, logp, logq);//encode(plain, vals, n, logp, logq);
	scheme.multAndEqual(cipher, cbin);
	scheme.reScaleByAndEqual(cipher, logp);

	Plaintext plnBin;

	//* Square each slot
	scheme.squareAndEqual(cipher);
	scheme.reScaleByAndEqual(cipher, logp);

	//* Sum subdistances
	Ciphertext subd;
	scheme.leftRotateFast(subd, cipher, r2);
	scheme.addAndEqual(cipher, subd);
	complex<double>* tmp10 = scheme.decrypt(secretKey, cipher);

	// Check range for square root
	for (long i = 0; i < points-1; ++i) {
			if (tmp10[i].real()>9){
			cout<<"distance "<<i<<" out of sqrt range : "<<tmp10[i].real()<<endl;
		}
			if (tmp10[i].real()<0.2){
			cout<<"distance "<<i<<" out of sqrt range inf : "<<tmp10[i].real()<<endl;
		}
	}

	//* Take square root of each slot
	Ciphertext csqrt;
	algo.function(csqrt, cipher, SQRT8, logp, 9); //SQRT9

	///* Show The subdistance vector
	complex<double>* dm = scheme.decrypt(secretKey, csqrt);

	///* Remove non necessary slots before summation
	Ciphertext cDes;
	scheme.encrypt(cDes, mDes, n, logp, logq);
	scheme.multAndEqual(csqrt, cDes);
	scheme.reScaleByAndEqual(csqrt, logp);

	///* Sum to slot 0
	for (long j =0; j< log(points-1)/log(2); j++) {
		Ciphertext rot;
		scheme.addLeftRotKey(secretKey, pow(2,j));
		scheme.leftRotateFast(rot, csqrt, pow(2,j));
		scheme.addAndEqual(csqrt, rot);
		//cout << "sum logq = "<<csqrt.logq << endl;
	}
	timeutils.stop(DISTANCE);

	//cout << "sum logq = "<<csqrt.logq << endl;

	// DECRYPTION
	timeutils.start(DEC);
	///* Decrypt
	complex<double>* decDir = scheme.decrypt(secretKey, csqrt);
	timeutils.stop(DEC);
	cout<<"distance = "<<decDir[0].real()*norm<<endl;

	double distance = 0;
	for (long i = 0; i < points-1; ++i) {
		distance += dm[i].real();
	}

	// Print for Latex
	// log n  | logq  |  logp  | RealDist | Distance  | error | t_i
	double result = decDir[0].real()*norm;
	cout<< logn <<" & "<< logq <<" & "<< logp <<" & "<< points <<" & "<<realDistance <<" & "<< decDir[0].real()*norm <<" & "<< distance*norm <<" & "<< floor((result*100./realDistance -100)*100)/100;//<<" & "<< floor(tenc/10)/100 <<" & "<< floor(tdist/10)/100 <<" & " << floor(tdec)/1000<<" & "<<counter;

}

void TestScheme::testWriteAndRead(long logq, long logp, long logSlots) {
	cout << "!!! START TEST WRITE AND READ !!!" << endl;

	cout << "!!! END TEST WRITE AND READ !!!" << endl;
}

void TestScheme::testBootstrap(long logq, long logQ, long logp, long logSlots, long logT) {
	/**
	 * Testing bootstrapping procedure for single real value
	 * number of modulus bits up: depends on parameters
	 * @param[in] logN: input parameter for Params class
	 * @param[in] logq: log of initial modulus
	 * @param[in] logQ: input parameter for Params class
	 * @param[in] logSlots: log of number of slots
	 * @param[in] nu: auxiliary parameter, corresonds to message bits (message bits is logq - nu)
	 * @param[in] logT: auxiliary parameter, corresponds to number of iterations in removeIpart (num of iterations is logI + logT)
	 * testBootstrap(long logq, long logQ, long logp, long logn, long logT); as of Nov18

	 */

	cout << "!!! START TEST BOOTSTRAP !!!" << endl;

	srand(time(NULL));
	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	timeutils.start("Key generating");
	scheme.addBootKey(secretKey, logSlots, logq + 4);
	timeutils.stop("Key generated");

	long slots = (1 << logSlots);
	complex<double>* mvec = EvaluatorUtils::randomComplexArray(slots);

	Ciphertext cipher;
	scheme.encrypt(cipher, mvec, slots, logp, logq);

	cout << "cipher logq before: " << cipher.logq << endl;

	scheme.modDownToAndEqual(cipher, logq);
	scheme.normalizeAndEqual(cipher);
	cipher.logq = logQ;
	cipher.logp = logq + 4;

	Ciphertext rot;
	timeutils.start("SubSum");
	for (long i = logSlots; i < logNh; ++i) {
		scheme.leftRotateFast(rot, cipher, (1 << i));
		scheme.addAndEqual(cipher, rot);
	}
	scheme.divByPo2AndEqual(cipher, logNh);
	timeutils.stop("SubSum");

	timeutils.start("CoeffToSlot");
	scheme.coeffToSlotAndEqual(cipher); // Issue here with default parameters
	timeutils.stop("CoeffToSlot");

	timeutils.start("EvalExp");
	scheme.evalExpAndEqual(cipher, logT);
	timeutils.stop("EvalExp");

	timeutils.start("SlotToCoeff");
	scheme.slotToCoeffAndEqual(cipher);
	timeutils.stop("SlotToCoeff");

	cipher.logp = logp;
	cout << "cipher logq after: " << cipher.logq << endl;

	complex<double>* dvec = scheme.decrypt(secretKey, cipher);

	StringUtils::compare(mvec, dvec, slots, "boot");

	cout << "!!! END TEST BOOTSRTAP !!!" << endl;
}

void TestScheme::testBootstrapSingleReal(long logq, long logQ, long logp, long logT) {
	cout << "!!! START TEST BOOTSTRAP SINGLE REAL !!!" << endl;

	srand(time(NULL));
//	SetNumThreads(8);
	TimeUtils timeutils;
	Ring ring;
	SecretKey secretKey(ring);
	Scheme scheme(secretKey, ring);

	timeutils.start("Key generating");
	scheme.addBootKey(secretKey, 0, logq + 4);
	timeutils.stop("Key generated");

	cout << "key ok" << endl;

	double mval = EvaluatorUtils::randomReal();

	Ciphertext cipher;
	scheme.encryptSingle(cipher, mval, logp, logq);

	cout << "cipher logq before: " << cipher.logq << endl;
	scheme.modDownToAndEqual(cipher, logq);
	scheme.normalizeAndEqual(cipher);
	cipher.logq = logQ;

	Ciphertext rot, cconj;
	timeutils.start("SubSum");
	for (long i = 0; i < logNh; ++i) {
		scheme.leftRotateFast(rot, cipher, 1 << i);
		scheme.addAndEqual(cipher, rot);
	}
	scheme.conjugate(cconj, cipher);
	scheme.addAndEqual(cipher, cconj);
	scheme.divByPo2AndEqual(cipher, logN);
	timeutils.stop("SubSum");

	timeutils.start("EvalExp");
	scheme.evalExpAndEqual(cipher, logT);
	timeutils.stop("EvalExp");

	cout << "cipher logq after: " << cipher.logq << endl;

	cipher.logp = logp;
	complex<double> dval = scheme.decryptSingle(secretKey, cipher);

	StringUtils::compare(mval, dval.real(), "boot");

	cout << "!!! END TEST BOOTSRTAP SINGLE REAL !!!" << endl;
}

void TestScheme::test() {
}

max_stars_repo_name: ldsec/CRISP

max_issues_repo_name: ldsec/CRISP

max_forks_repo_name: ldsec/CRISP


text:
#ifndef pear_func_hpp
#define pear_func_hpp

#include <Eigen/Core>
#include <Eigen/Sparse>

// TYPE DEFINITIONS
typedef Eigen::MatrixXd Mat;
typedef Eigen::VectorXd Vec;
typedef Eigen::MatrixXi MatI;
typedef Eigen::VectorXi VecI;
typedef Eigen::SparseMatrix<double, Eigen::RowMajor> SpMat;

namespace pear {
void fun_diff(Vec &Cu, Vec &Cv, Vec &Ru, Vec &Rv, Mat &RudCu, Mat &RudCv,
              Mat &RvdCu, Mat &RvdCv);
} // namespace pear

#endif

ext: hpp


text:
#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <memory>
#include <boost/format.hpp>
#include <tssplitter/ts/packet.hpp>
#include <tssplitter/filename.hpp>

namespace tssplitter { namespace ts {
  class splitter {
    constexpr static auto IO_BUFFER_SIZE = ts::packet::SIZE * 1024 * 10; // 1.88MB

    filename ipath;
    filename opath;
    std::ifstream ifs;
    std::ofstream ofs;
    std::shared_ptr<char> ifs_buffer;
    std::shared_ptr<char> ofs_buffer;

    uint32_t count;
    uint32_t video_pid;
    uint32_t audio_pid;

    enum pmt_status_type {
      NO_CHANGE = 0,
      FIRST     = 1,
      CHANGE    = 2,
    };

  public:
    splitter(std::string ipath, std::string opath);
    int execute(void);

  private:
    uint32_t get_pmt_pid(void);
    void find_pmt(uint32_t pid, std::function<void(psi::pmt *)> callback);
    uint32_t get_pmt_status(void);

    void wait_stream(std::function<bool(void)> callback);
    void each_packet(std::function<bool(ts::packet &)> callback);
    void read_packet(ts::packet & packet);
    void write_packet(ts::packet & packet);
    bool open_istream(void);
    bool open_ostream(void);
  };
}}


text:
#include "stdafx.hxx"

#include "rdo-directory-statistics.hxx"
#include "krn.hxx"
#include "util/unicode/boost-filesystem-util.hxx"
#include "util/unicode/boost-program-options-util.hxx"
#include "rdo-recursive-copy.hxx"
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/find.hpp>
#include <exception>
#include <filesystem>
#include <locale>
#include <string>
#include <vector>

using namespace boost::algorithm;
using namespace std::filesystem;
using namespace boost::program_options;
using std::string;
using std::vector;

class rec_dir_op_dir_statistics: public recursive_dir_op
{
public:
	rec_dir_op_dir_statistics(bfs::path& isrc_dir);
	void on_start(mws_sp<dir_node> dir);
	void on_finish(mws_sp<dir_node> dir);
	bool on_entering_dir(mws_sp<dir_node> dir);
	void on_leaving_dir(mws_sp<dir_node> dir);
	void apply_to_file(mws_sp<file_node> file);

private:
	bfs::path src_dir;
	int file_count;
	int directory_count;
	uint64_t total_file_size;
	uint64_t max_file_size;
	path max_file;
	uint64_t min_file_size;
	path min_file;
};

std::string cmd_mod_dir_statistics::get_module_name()
{
	return "directory-statistics";
}

const string SOURCE_PATH			= "source-path";

boost::program_options::options_description cmd_mod_dir_statistics::get_options_description()
{
	options_description desc(trs("available options for module [{}]", get_module_name()));

	desc.add_options()
		(SOURCE_PATH.c_str(), unicodevalue<unicodestring>()->required(), "source path. must be an absolute path")
	;

	return desc;
}

mws_sp<long_operation> cmd_mod_dir_statistics::run(const vector<unicodestring>& args)
{
	options_description desc = get_options_description();
	variables_map vm;
	unicode_parsed_options parsed = unicode_command_line_parser(args).options(desc).run();

	store(parsed, vm);
	notify(vm);

   std::filesystem::path srcPath(vm[SOURCE_PATH].as<unicodestring>());

	mws_sp<long_operation> lop = mws_sp<long_operation>(new long_op_dir_statistics(srcPath));

	return lop;
}

long_op_dir_statistics::long_op_dir_statistics(path& isrc_path)
{
	src_path = isrc_path;
}

void long_op_dir_statistics::run()
{
	if (exists(src_path))
	{
		if (is_directory(src_path))
		{
			utrx(untr("starting longOpDirStatistics in directory [{}]"), path2string(src_path));

			mws_sp<directory_tree> dirtree = directory_tree::new_directory_tree(src_path);
			rec_dir_op_dir_statistics rdo(src_path);

			dirtree->recursive_apply(rdo);
		}
		else
		{
         mws_throw mws_exception(trs("longOpDirStatistics: {} is not a directory", src_path.string()));
		}
	}
	else
	{
      mws_throw mws_exception(trs("longOpDirStatistics: {} does not exist", src_path.string()));
	}
}

rec_dir_op_dir_statistics::rec_dir_op_dir_statistics(path& isrc_dir)
{
	src_dir = isrc_dir;
}

void rec_dir_op_dir_statistics::on_start(mws_sp<dir_node> dir)
{
	file_count = directory_count = total_file_size = 0;
    min_file_size = 0xffffffffU;
	max_file_size = 0;
}

void rec_dir_op_dir_statistics::on_finish(mws_sp<dir_node> dir)
{
	trx("directories [{0}], files [{1}], all-file size [{2}]", directory_count, file_count, total_file_size);
	utrx(untr("smallest file [{0}] size [{1}], largest file [{2}] size [{3}]"), path2string(min_file), min_file_size, path2string(max_file), max_file_size);
}

bool rec_dir_op_dir_statistics::on_entering_dir(mws_sp<dir_node> dir)
{
	return true;
}

void rec_dir_op_dir_statistics::on_leaving_dir(mws_sp<dir_node> dir)
{
	directory_count++;
}

void rec_dir_op_dir_statistics::apply_to_file(mws_sp<file_node> file)
{
	uint64_t fileSize = file_size(file->abs_file_path);

	if(fileSize > max_file_size)
	{
		max_file_size = fileSize;
		max_file = file->rel_file_path;
	}
	else if(fileSize < min_file_size)
	{
		min_file_size = fileSize;
		min_file = file->rel_file_path;
	}

	total_file_size += fileSize;
	file_count++;
}

ext: cxx

max_stars_repo_name: indigoabstract/appplex

max_issues_repo_name: indigoabstract/appplex

max_forks_repo_name: indigoabstract/appplex


text:
//==============================================================================
//         Copyright 2003 - 2012   LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2012   LRI    UMR 8623 CNRS/Univ Paris Sud XI
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#define NT2_UNIT_MODULE "nt2 boost.simd.arithmetic toolbox - fma/scalar Mode"

//////////////////////////////////////////////////////////////////////////////
// unit test behavior of boost.simd.arithmetic components in scalar mode
//////////////////////////////////////////////////////////////////////////////
/// created by jt the 01/12/2010
///
#include <nt2/arithmetic/include/functions/fma.hpp>
#include <boost/dispatch/functor/meta/call.hpp>
#include <nt2/sdk/unit/tests/relation.hpp>
#include <nt2/sdk/unit/tests/type_expr.hpp>
#include <nt2/sdk/unit/tests/ulp.hpp>
#include <nt2/sdk/unit/module.hpp>
#include <nt2/include/constants/inf.hpp>
#include <nt2/include/constants/minf.hpp>
#include <nt2/include/constants/one.hpp>
#include <nt2/include/constants/mone.hpp>
#include <nt2/include/constants/zero.hpp>
#include <nt2/include/constants/two.hpp>
#include <nt2/include/constants/nan.hpp>
#include <nt2/include/constants/minf.hpp>

NT2_TEST_CASE_TPL ( fma_real__3_0, BOOST_SIMD_REAL_TYPES)
{

  using nt2::fma;
  using nt2::tag::fma_;
  typedef std::complex<T> cT;
  typedef typename boost::dispatch::meta::call<fma_(cT,cT,cT)>::type r_t;
  typedef typename nt2::meta::scalar_of<r_t>::type sr_t;

  // return type conformity test
  NT2_TEST_TYPE_IS( typename boost::dispatch::meta::call<fma_(cT,cT,cT)>::type, cT );

  // specific values tests
  NT2_TEST_ULP_EQUAL(fma(cT(nt2::Inf<T>()), cT(nt2::Inf<T>()), cT(nt2::Inf<T>())), cT(nt2::Inf<T>()), 0);
  NT2_TEST_EQUAL(fma(cT(nt2::Minf<T>()), cT(nt2::Minf<T>()), cT(nt2::Minf<T>())), cT(nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(cT(nt2::Mone<T>()), cT(nt2::Mone<T>()), cT(nt2::Mone<T>())), cT(nt2::Zero<T>()));
  NT2_TEST_EQUAL(fma(cT(nt2::Nan<T>()), cT(nt2::Nan<T>()), cT(nt2::Nan<T>())), cT(nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(cT(nt2::One<T>()), cT(nt2::One<T>()), cT(nt2::One<T>())), cT(nt2::Two<T>()));
  NT2_TEST_EQUAL(fma(cT(nt2::Zero<T>()), cT(nt2::Zero<T>()), cT(nt2::Zero<T>())), cT(nt2::Zero<T>()));
} // end of test for floating_

NT2_TEST_CASE_TPL ( fma_various,  BOOST_SIMD_REAL_TYPES)
{

  using nt2::fma;
  using nt2::tag::fma_;
  typedef std::complex<T> cT;
  typedef typename nt2::meta::as_imaginary<T>::type iT;

  std::cout << "0\n";
  NT2_TEST_EQUAL(fma(T(2), T(3), T(4)), T(10));
  NT2_TEST_EQUAL(fma(cT(2), cT(3), cT(4)), cT(10));
  NT2_TEST_EQUAL(    cT(2)*cT(3)+cT(4), cT(10));
  std::cout << "1\n";
  NT2_TEST_EQUAL(fma(cT(2), cT(3), iT(4)), cT(6, 4));
  NT2_TEST_EQUAL(fma(cT(2), cT(3), cT(0, 4)), cT(6, 4));
  NT2_TEST_EQUAL(    cT(2)*cT(3)+cT(0, 4), cT(6, 4));
  std::cout << "2\n";
  NT2_TEST_EQUAL(fma(cT(2), iT(3), cT(4)), cT(4, 6));
  NT2_TEST_EQUAL(fma(cT(2), cT(0, 3), cT(4)), cT(4, 6));
  NT2_TEST_EQUAL((cT(2)*cT(0, 3)+cT(4)), cT(4, 6));
  std::cout << "3\n";
  NT2_TEST_EQUAL(fma(iT(2), cT(3), cT(4)), cT(4, 6));
  NT2_TEST_EQUAL(fma(cT(0, 2), cT(3), cT(4)), cT(4, 6));
  NT2_TEST_EQUAL((cT(0, 2)* cT(3)+cT(4)), cT(4, 6));
  std::cout << "4\n";
  NT2_TEST_EQUAL(fma(cT(2), iT(3), iT(4)), cT(0, 10));
  NT2_TEST_EQUAL(fma(cT(2), cT(0, 3), cT(0, 4)), cT(0, 10));
  NT2_TEST_EQUAL((cT(2)* cT(0, 3)+ cT(0, 4)), cT(0, 10));
  std::cout << "5\n";
  NT2_TEST_EQUAL(fma(iT(2), iT(3), cT(4, 5)), cT(-2, 5));
  NT2_TEST_EQUAL(fma(cT(0, 2), cT(0, 3), cT(4, 5)), cT(-2, 5));
  NT2_TEST_EQUAL((cT(0, 2)* cT(0, 3)+ cT(4, 5)), cT(-2, 5));
  std::cout << "6\n";
  NT2_TEST_EQUAL(fma(iT(2), cT(3, 5), iT(4)), cT(-10, 10));
  NT2_TEST_EQUAL(fma(cT(0, 2), cT(3, 5), cT(0, 4)), cT(-10, 10));
  NT2_TEST_EQUAL((cT(0, 2)* cT(3, 5)+ cT(0, 4)), cT(-10, 10));
  std::cout << "7\n";
  NT2_TEST_EQUAL(fma(iT(2), iT(3),iT(4)), cT(-6, 4));
  NT2_TEST_EQUAL(fma(cT(0, 2), cT(0, 3), cT(0, 4)), cT(-6, 4));
  NT2_TEST_EQUAL((cT(0, 2)*cT(0, 3)+cT(0, 4)), cT(-6, 4));
  std::cout << "8\n";
  NT2_TEST_EQUAL(fma(T(2), cT(5, 3),cT(6, 4)), cT(16, 10));
  NT2_TEST_EQUAL(fma(cT(2), cT(5, 3), cT(6, 4)), cT(16, 10));
  NT2_TEST_EQUAL((cT(2)*cT(5, 3)+cT(6, 4)), cT(16, 10));
  std::cout << "9\n";
  NT2_TEST_EQUAL(fma(T(2), cT(5, 3),cT(6, 4)), cT(16, 10));
  NT2_TEST_EQUAL(fma(cT(2), cT(5, 3), cT(6, 4)), cT(16, 10));
  NT2_TEST_EQUAL((cT(2)*cT(5, 3)+cT(6, 4)), cT(16, 10));
  std::cout << "10\n";
  NT2_TEST_EQUAL(fma(cT(2, 3), cT(5, 3),T(6)), cT(7, 21));
  NT2_TEST_EQUAL(fma(cT(2, 3), cT(5, 3), cT(6)), cT(7, 21));
  NT2_TEST_EQUAL((cT(2, 3)*cT(5, 3)+cT(6)), cT(7, 21));
  std::cout << "11\n";
  NT2_TEST_EQUAL(fma(cT(2, 3), T(5),T(6)), cT(16, 15));
  NT2_TEST_EQUAL(fma(cT(2, 3), cT(5), cT(6)), cT(16, 15));
  NT2_TEST_EQUAL((cT(2, 3)*cT(5)+cT(6)), cT(16, 15));
  std::cout << "12\n";
  NT2_TEST_EQUAL(fma(T(2), cT(5, 3),T(6)), cT(16, 6));
  NT2_TEST_EQUAL(fma(cT(2), cT(5, 3), cT(6)), cT(16, 6));
  NT2_TEST_EQUAL((cT(2)*cT(5, 3)+cT(6)), cT(16, 6));
  std::cout << "13\n";
  NT2_TEST_EQUAL(fma(T(2), T(5),cT(6, 2)), cT(16, 2));
  NT2_TEST_EQUAL(fma(cT(2), cT(5), cT(6, 2)), cT(16, 2));
  NT2_TEST_EQUAL((cT(2)*cT(5)+cT(6, 2)), cT(16, 2));
  std::cout << "14\n";
  NT2_TEST_EQUAL(fma(T(2), iT(5),cT(6, 2)), cT(6, 12));
  NT2_TEST_EQUAL(fma(cT(2), cT(0, 5), cT(6, 2)), cT(6, 12));
  NT2_TEST_EQUAL((cT(2)*cT(0, 5)+cT(6, 2)), cT(6, 12));
  std::cout << "15\n";
  NT2_TEST_EQUAL(fma(T(2), cT(2, 5),iT(2)), cT(4, 12));
  NT2_TEST_EQUAL(fma(cT(2), cT(2, 5), cT(0, 2)), cT(4, 12));
  NT2_TEST_EQUAL((cT(2)*cT(2, 5)+cT(0, 2)), cT(4, 12));
  std::cout << "16\n";
  NT2_TEST_EQUAL(fma(cT(2, 5), iT(5),T(2)), cT(-23, 10));
  NT2_TEST_EQUAL(fma(cT(2, 5), cT(0, 5), cT(2)), cT(-23, 10));
  NT2_TEST_EQUAL((cT(2, 5)*cT(0, 5)+cT(2)), cT(-23, 10));
  std::cout << "17\n";
  NT2_TEST_EQUAL(fma(iT(5), cT(2, 5),T(2)), cT(-23, 10));
  NT2_TEST_EQUAL(fma(cT(0, 5), cT(2, 5), cT(2)), cT(-23, 10));
  NT2_TEST_EQUAL((cT(0, 5)*cT(2, 5)+cT(2)), cT(-23, 10));
  std::cout << "18\n";
  NT2_TEST_EQUAL(fma(cT(2, 5), T(3),iT(2)), cT(6, 17));
  NT2_TEST_EQUAL(fma(cT(2, 5), cT(3, 0), cT(0, 2)), cT(6, 17));
  NT2_TEST_EQUAL((cT(2, 5)*cT(3, 0)+cT(0, 2)), cT(6, 17));
  std::cout << "19\n";
  NT2_TEST_EQUAL(fma(iT(5), T(3),cT(6, 2)), cT(6, 17));
  NT2_TEST_EQUAL(fma(cT(0, 5), cT(3), cT(6, 2)), cT(6, 17));
  NT2_TEST_EQUAL((cT(0, 5)*cT(3, 0)+cT(6, 2)), cT(6, 17));

} // end of test for floating_

NT2_TEST_CASE_TPL ( fma_various_invalid, (float))//BOOST_SIMD_REAL_TYPES)
{

  using nt2::fma;
  using nt2::tag::fma_;
  typedef std::complex<T> cT;
  typedef typename nt2::meta::as_imaginary<T>::type iT;

  // specific values tests

  std::cout << "0 ccc \n";
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(3), cT(4)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(3), cT(4)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(cT(2), cT(3), cT(4)), cT(10));
  NT2_TEST_EQUAL(fma(cT(2, 3), cT(3, 1), cT(2, 4)), cT(5, 15));

  NT2_TEST_EQUAL(fma(cT(0, nt2::Inf<T>()), cT(0), cT(3, 4)), cT(3, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(cT(0),cT(0, nt2::Inf<T>()), cT(4)), cT(4, nt2::Nan<T>()));

  NT2_TEST_EQUAL(fma(cT(1, nt2::Inf<T>()), cT(0), cT(3, nt2::Minf<T>())), cT(3, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(cT(0),cT(1, nt2::Inf<T>()), cT(4)), cT(4, nt2::Nan<T>()));

  NT2_TEST_EQUAL(fma(nt2::Inf<T>(), T(3), T(4)), nt2::Inf<T>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(3), cT(nt2::Minf<T>())), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(cT(1),nt2::Inf<cT>(), cT(nt2::Minf<T>())), cT(nt2::Nan<T>(), 0));
  NT2_TEST_EQUAL(fma(cT(1),cT(0, nt2::Inf<T>()), cT(nt2::Minf<T>())), cT(nt2::Minf<T>(), nt2::Inf<T>()));

  NT2_TEST_EQUAL(   nt2::multiplies(nt2::Inf<cT>(), cT(3))+cT(4), nt2::Inf<cT>());

  std::cout << "1 cci\n";
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(3), iT(0)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(cT(2), cT(3), cT(0, 4)), cT(6, 4));
  NT2_TEST_EQUAL(    nt2::plus(nt2::multiplies(nt2::Inf<cT>(), cT(3)), iT(0)), nt2::Inf<cT>());

  std::cout << "2 cic \n";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(), T(0), cT(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), iT(0), cT(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(0), cT(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(nt2::Inf<cT>(), iT(0)), cT(4)), nt2::Nan<cT>());
  std::cout << "3 icc\n";
  NT2_TEST_EQUAL(fma(iT(0), nt2::Inf<cT>(), cT(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(cT(0), nt2::Inf<cT>(), cT(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(iT(0), nt2::Inf<cT>()), cT(4)), nt2::Nan<cT>());

  std::cout << "4 cii\n";
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), iT(0), cT(0, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), iT(1), iT(4)), cT(0, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(0, 1), iT(4)), cT(0, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(0), cT(0, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(cT(0), cT(0), nt2::Inf<cT>()),  nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(0), nt2::Inf<cT>()),  nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(nt2::Minf<cT>(), cT(1), nt2::Inf<cT>()),  nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(1), nt2::Inf<cT>()),  nt2::Nan<cT>());
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(nt2::Inf<cT>(), cT(0)), cT(0, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(nt2::Inf<cT>(), iT(0)), cT(0, 4)), cT(nt2::Nan<T>(), 4));

  std::cout << "5 iic\n";
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(0), cT(4, 5)), cT(nt2::Nan<T>(), 5));
  NT2_TEST_EQUAL(fma(cT(0), nt2::Inf<cT>(), cT(4, 5)), cT(nt2::Nan<T>(), 5));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(nt2::Inf<cT>(), cT(0)), cT(4, 5)), cT(nt2::Nan<T>(), 5));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(nt2::Inf<cT>(), iT(0)), cT(4, 5)), cT(nt2::Nan<T>(), 5));
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(0), cT(4, 4)), cT(4, nt2::Nan<T>()));

  std::cout << "6 ici\n";
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), cT(0), iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(cT(0), iT(nt2::Inf<T>()), iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(0), cT(3, 4)), cT(3, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(iT(0), iT(nt2::Inf<T>()), cT(3, 4)), cT(3, nt2::Nan<T>()));

  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(0), iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma( iT(0),iT(nt2::Inf<T>()),iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(1), iT(4)), cT(nt2::Minf<T>(), 4));
  NT2_TEST_EQUAL(fma( iT(1),iT(nt2::Inf<T>()),iT(4)), cT(nt2::Minf<T>(), 4));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(cT(0,nt2::Inf<T>()), cT(0)), cT(0, 4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(iT(nt2::Inf<T>()), cT(0)), cT(0, 4)), cT(0, nt2::Nan<T>()));

  std::cout << "7 iii\n";
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(3),iT(4)), cT(nt2::Minf<T>(), 4));
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(0),iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(iT(nt2::Inf<T>()), iT(0)), iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(iT(nt2::Inf<T>()), iT(3)), iT(4)), cT(nt2::Minf<T>(), 4));

  std::cout << "8\n acc";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(), cT(0),cT(6, 4)),     cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(), iT(0), cT(6, 4)),    cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(), cT(0, 3),cT(6, 4)),  cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(), iT(3), cT(6, 4)),    cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(T(0),          nt2::Inf<cT>(),      cT(6, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(T(0),          iT(nt2::Inf<T>()),   cT(6, 4)), cT(6, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  cT(1), cT( 3, 4)), cT(nt2::Inf<T>(), 4));
  NT2_TEST_EQUAL(fma(T(1), cT(nt2::Inf<T>()),  cT(4, 4)), cT(nt2::Inf<T>(), 4));

  std::cout << "9 cac\n";
  NT2_TEST_EQUAL(fma( cT(0)                ,nt2::Inf<T>(),cT(6, 4)),     cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma( iT(0)                ,nt2::Inf<T>(),cT(6, 4)),    cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma( iT(0)                ,nt2::Inf<cT>(),cT(6, 4)),    cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma( cT(0, 3)             ,nt2::Inf<T>(),cT(6, 4)),  cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma( iT(3)                ,nt2::Inf<T>(),cT(6, 4)),    cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma( nt2::Inf<cT>(),       T(0),         cT(6, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma( iT(nt2::Inf<T>()),    T(0),         cT(6, 4)), cT(6, nt2::Nan<T>()));

  std::cout << "10 cca\n";
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(3), T(4)),                     nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(cT(3),                     nt2::Inf<cT>(), T(4)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(cT(4),                     nt2::Inf<cT>(), cT(3)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), T(4), cT(3)),                     nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(0), T(4)),                     nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(cT(0),                     nt2::Inf<cT>(), T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(cT(0),                     nt2::Inf<cT>(), cT(3)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), T(4), cT(3)),                     nt2::Inf<cT>());

  std::cout << "11 caa\n";
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), T(3),           T(4)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(cT(3, 4),        nt2::Inf<T>(), T(4)), cT(nt2::Inf<T>(), nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(cT(4),           nt2::Inf<T>(), T(3)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(),  T(0),          T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(cT(0),           nt2::Inf<T>(), T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(),  T(4),          T(3)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(cT(0, nt2::Inf<T>()), T(4),     T(3)), cT(3, nt2::Inf<T>()));

  std::cout << "12 aca\n";
  NT2_TEST_EQUAL(fma(T(3),         nt2::Inf<cT>(),   T(4)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),cT(3, 4),         T(4)), cT(nt2::Inf<T>(), nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),cT(4),            T(3)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(T(0),         nt2::Inf<cT>(),   T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),cT(0),            T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(T(4),         nt2::Inf<cT>(),   T(3)), nt2::Inf<cT>());
  NT2_TEST_EQUAL(fma(T(4), cT(0, nt2::Inf<T>()), T(3)), cT(3, nt2::Inf<T>()));

  std::cout << "13 aac\n";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  T(0), cT(6, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(T(0), nt2::Inf<T>(),  cT(6, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  T(1), cT(6, 4)), cT(nt2::Inf<T>(), 4));
  NT2_TEST_EQUAL(fma(T(1), nt2::Inf<T>(),  cT(6, 4)), cT(nt2::Inf<T>(), 4));

  std::cout << "14\n aic";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(0), cT(6, 4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(T(0), iT(nt2::Inf<T>()),  cT(6, 4)), cT(6, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(1), cT(6, 4)), cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(T(1), iT(nt2::Inf<T>()),  cT(6, 4)), cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(0), cT(6)), cT(nt2::Nan<T>(), 0));
  NT2_TEST_EQUAL(fma(T(0), iT(nt2::Inf<T>()),  cT(6)), cT(6, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(1), cT(6)), cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(T(1), iT(nt2::Inf<T>()),  cT(6)), cT(6, nt2::Inf<T>()));

  std::cout << "15 aci\n";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  cT(0), iT(4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(T(0), cT(nt2::Inf<T>()),  iT(4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  cT(1), iT(4)), cT(nt2::Inf<T>(), 4));
  NT2_TEST_EQUAL(fma(T(1), cT(nt2::Inf<T>()),  iT(4)), cT(nt2::Inf<T>(), 4));

  std::cout << "16 cia \n";
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), iT(0), T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(nt2::Inf<cT>(), cT(0), T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(cT(0), iT(nt2::Inf<T>()), T(4)), cT(4, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(cT(0), cT(0, nt2::Inf<T>()), T(4)),cT(4, nt2::Nan<T>()));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(nt2::Inf<cT>(), iT(0)), T(4)), nt2::Nan<cT>());

  std::cout << "17 ica \n";
  NT2_TEST_EQUAL(fma(iT(0), nt2::Inf<cT>(), T(4)), nt2::Nan<cT>());
  NT2_TEST_EQUAL(fma(cT(0), nt2::Inf<cT>(), T(4)), nt2::Nan<cT>());

  std::cout << "18 cai \n";
  NT2_TEST_EQUAL(fma( cT(0),              nt2::Inf<T>(), iT(4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma( cT(nt2::Inf<T>()),  T(0),          iT(4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma( cT(1),              nt2::Inf<T>(), iT(4)), cT(nt2::Inf<T>(), 4));
  NT2_TEST_EQUAL(fma( cT(nt2::Inf<T>()),  T(1),          iT(4)), cT(nt2::Inf<T>(), 4));

  std::cout << "19 iac \n";
  NT2_TEST_EQUAL(fma( iT(0),              nt2::Inf<T>(), cT(6, 4)),   cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma( iT(nt2::Inf<T>()),  T(0),          cT(6, 4)), cT(6, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma( iT(1),   nt2::Inf<T>(), cT(6, 4)), cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma( iT(nt2::Inf<T>()),  T(1),          cT(6, 4)), cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma( iT(0),              nt2::Inf<T>(), cT(6)),      cT(nt2::Nan<T>(), 0));
  NT2_TEST_EQUAL(fma( iT(nt2::Inf<T>()),  T(0),          cT(6)), cT(6, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma( iT(1),              nt2::Inf<T>(), cT(6)),      cT(6, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma( iT(nt2::Inf<T>()),  T(1),          cT(6)), cT(6, nt2::Inf<T>()));

  std::cout << "20 aai \n";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  T(0), iT(4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(T(0), nt2::Inf<T>(),  iT(4)), cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  T(1), iT(4)), cT(nt2::Inf<T>(), 4));
  NT2_TEST_EQUAL(fma(T(1), nt2::Inf<T>(),  iT(4)), cT(nt2::Inf<T>(), 4));

  std::cout << "21 aia \n";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(0), T(4)),    cT(nt2::Nan<T>(), 0));
  NT2_TEST_EQUAL(fma(T(0), iT(nt2::Inf<T>()),  T(4)), cT(4, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(1), T(4)),    cT(4, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(T(1), iT(nt2::Inf<T>()),  T(4)), cT(4, nt2::Inf<T>()));

  std::cout << "22 iaa \n";
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()),  T(0), T(4)),    cT(4, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(iT(0), nt2::Inf<T>(),  T(4)),       cT(nt2::Nan<T>(), 0));
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()),  T(1), T(4)),    cT(4, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(iT(1), T(nt2::Inf<T>()),  T(4)),    cT(4, nt2::Inf<T>()));

  std::cout << "23 aii \n";
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(0), iT(4)),    cT(nt2::Nan<T>(), 4));
  NT2_TEST_EQUAL(fma(T(0), iT(nt2::Inf<T>()),  iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(nt2::Inf<T>(),  iT(1), iT(4)),    cT(0, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(T(1), iT(nt2::Inf<T>()),  iT(4)), cT(0, nt2::Inf<T>()));

  std::cout << "24 iia \n";
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(3),T(4)), cT(nt2::Minf<T>(), 0));
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), iT(0),T(4)), cT(4, nt2::Nan<T>()));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(iT(nt2::Inf<T>()), iT(0)), T(4)), cT(4, nt2::Nan<T>()));
  NT2_TEST_EQUAL(nt2::plus(nt2::multiplies(iT(nt2::Inf<T>()), iT(3)), T(4)), cT(nt2::Minf<T>(), 0));

  std::cout << "25 iai \n";
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), T(3),iT(4)), cT(0, nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(iT(nt2::Inf<T>()), T(0),iT(4)), cT(0, nt2::Nan<T>()));
  NT2_TEST_EQUAL(fma(iT(3), nt2::Inf<T>(),iT(4)),     cT(0,  nt2::Inf<T>()));
  NT2_TEST_EQUAL(fma(iT(0), nt2::Inf<T>(),iT(4)),     cT(nt2::Nan<T>(), 4));
} // end of test for floating_