<commit_before>#ifndef TRWS_INTERFACE_HXX_
#define TRWS_INTERFACE_HXX_
#include <opengm/inference/inference.hxx>
#include <opengm/inference/trws/trws_base.hxx>
#include <opengm/inference/trws/trws_reparametrization.hxx>

namespace opengm{

template<class GM>
struct TRWSi_Parameter : public trws_base::MaxSumTRWS_Parameters<typename GM::ValueType>
{
	typedef typename GM::ValueType ValueType;
	typedef trws_base::MaxSumTRWS_Parameters<ValueType> parent;
	typedef trws_base::DecompositionStorage<GM> Storage;

	TRWSi_Parameter(size_t maxIternum=0,
			        typename Storage::StructureType decompositionType = Storage::GENERALSTRUCTURE,
			        ValueType precision=1.0,
			        bool absolutePrecision=true,
			        bool verbose=false)
	:parent(maxIternum,precision,absolutePrecision),
	 decompositionType_(decompositionType),
	 verbose_(verbose)
{
}

	typename Storage::StructureType decompositionType_;
	bool verbose_;

	size_t& maxNumberOfIterations(){return parent::maxNumberOfIterations_;}
	const size_t& maxNumberOfIterations()const {return parent::maxNumberOfIterations_;}

	ValueType& precision(){return parent::precision_;}
	const ValueType& precision()const{return parent::precision_;}

	bool& isAbsolutePrecision(){return parent::absolutePrecision_;};//true for absolute precision, false for relative w.r.t. dual value
	const bool& isAbsolutePrecision()const{return parent::absolutePrecision_;};//true for absolute precision, false for relative w.r.t. dual value

	ValueType& minRelativeDualImprovement(){return parent::minRelativeDualImprovement_;}
	const ValueType& minRelativeDualImprovement()const{return parent::minRelativeDualImprovement_;}

	bool& fastComputations(){return parent::fastComputations_;}
	const bool& fastComputations()const{return parent::fastComputations_;}

	bool& canonicalNormalization(){return parent::canonicalNormalization_;};
	const bool& canonicalNormalization()const{return parent::canonicalNormalization_;};

	typename Storage::StructureType& decompositionType(){return decompositionType_;}
	const typename Storage::StructureType& decompositionType()const{return decompositionType_;}

	bool& verbose(){return verbose_;};
	const bool& verbose()const{return verbose_;};

#ifdef TRWS_DEBUG_OUTPUT
	  void print(std::ostream& fout)const
	  {
			fout << "maxNumberOfIterations="<<maxNumberOfIterations()<<std::endl;
			fout <<"precision="<<precision()<<std::endl;
			fout <<"isAbsolutePrecision="<<isAbsolutePrecision()<<std::endl;
			fout <<"minRelativeDualImprovement="<<minRelativeDualImprovement()<<std::endl;
			fout <<"fastComputations="<<fastComputations()<<std::endl;
			fout <<"canonicalNormalization="<<canonicalNormalization()<<std::endl;
			  if (decompositionType()==Storage::GENERALSTRUCTURE)
				  fout <<"decompositionType=" <<"GENERAL"<<std::endl;
			  else if (decompositionType()==Storage::GRIDSTRUCTURE)
				  fout <<"decompositionType=" <<"GRID"<<std::endl;
			  else
				  fout <<"decompositionType=" <<"UNKNOWN"<<std::endl;
			fout <<"verbose="<<verbose()<<std::endl;
			fout <<"treeAgreeMaxStableIter="<<parent::treeAgreeMaxStableIter_<<std::endl;
	  }
#endif
};

//! [class trwsi]
/// TRWSi - tree-reweighted sequential message passing
/// Based on the paper:
/// V. Kolmogorov
/// Convergent tree-reweighted message passing for energy minimization. IEEE Trans. on PAMI, 28(10):1568–1583, 2006.
///
/// it provides:
/// * primal integer approximate solution for MRF energy minimization problem
/// * lower bound for a solution of the problem.
///
///
/// TODO: Code can be significantly speeded up!
///
/// Corresponding author: Bogdan Savchynskyy
///
///\ingroup inference

template<class GM, class ACC>
class TRWSi : public Inference<GM, ACC>
{
public:
  typedef ACC AccumulationType;
  typedef GM GraphicalModelType;
  OPENGM_GM_TYPE_TYPEDEFS;
  typedef trws_base::MaxSumTRWS<GM, ACC> Solver;
  typedef trws_base::DecompositionStorage<GM> Storage;
  typedef visitors::ExplicitVerboseVisitor<TRWSi<GM, ACC> > VerboseVisitorType;
  typedef visitors::ExplicitTimingVisitor<TRWSi<GM, ACC> >  TimingVisitorType;
  typedef visitors::ExplicitEmptyVisitor< TRWSi<GM, ACC> >  EmptyVisitorType;

  typedef TRWSi_Parameter<GM> Parameter;
//  typedef typename Solver::ReparametrizerType ReparametrizerType;
  typedef TRWS_Reparametrizer<Storage,ACC> ReparametrizerType;
  typedef typename Storage::DDVectorType DDVectorType;

  TRWSi(const GraphicalModelType& gm, const Parameter& param
#ifdef TRWS_DEBUG_OUTPUT
		  ,std::ostream& fout=std::cout
#endif
		  ,const DDVectorType* pddvector=0
  ):
						  _storage(gm,param.decompositionType_,pddvector),
						  _solver(_storage,param
#ifdef TRWS_DEBUG_OUTPUT
								  ,(param.verbose_ ? fout : *OUT::nullstream::Instance()) //fout
#endif
						  ){
#ifdef TRWS_DEBUG_OUTPUT
	  std::ostream& out=(param.verbose_ ? fout : *OUT::nullstream::Instance());
	  out << "Parameters of the "<< name() <<" algorithm:"<<std::endl;
	  param.print(out);
#endif

	  if (param.maxNumberOfIterations_==0) throw
			  std::runtime_error("TRWSi: Maximal number of iterations (> 0) has to be specified!");
  }
  std::string name() const{ return "TRWSi"; }
  const GraphicalModelType& graphicalModel() const { return _storage.masterModel(); }
  InferenceTermination infer(){
	  _solver.infer();
	  return NORMAL;
  };

  template<class VISITOR> InferenceTermination infer(VISITOR & visitor){
	  trws_base::VisitorWrapper<VISITOR,TRWSi<GM, ACC> > visiwrap(&visitor,this);
	  _solver.infer(visiwrap);
	  return NORMAL;
  };

  InferenceTermination arg(std::vector<LabelType>& out, const size_t = 1) const
	  {
	  out = _solver.arg();
	  return opengm::NORMAL;}
  virtual ValueType bound() const{return _solver.bound();}
  virtual ValueType value() const{return _solver.value();}
  void getTreeAgreement(std::vector<bool>& out,std::vector<LabelType>* plabeling=0,std::vector<std::vector<LabelType> >* ptreeLabelings=0){_solver.getTreeAgreement(out,plabeling,ptreeLabelings);}
  //const Storage& getDecompositionStorage()const{return _storage;}
  Storage& getDecompositionStorage(){return _storage;}
  const typename Solver::FactorProperties& getFactorProperties()const {return _solver.getFactorProperties();}

//  ReparametrizerType* getReparametrizer(const typename ReparametrizerType::Parameter& params= typename ReparametrizerType::Parameter())const
//  {return _solver.getReparametrizer(params);}

  ReparametrizerType * getReparametrizer(const typename ReparametrizerType::Parameter& params=typename ReparametrizerType::Parameter())//const //TODO: make it constant
  {return new ReparametrizerType(_storage,_solver.getFactorProperties(),params);}

  void getDDVector(DDVectorType* pddvector)const{_storage.getDDVector(pddvector);}

  private:
   Storage _storage;
   Solver _solver;
};

}
#endif

<commit_msg>TRWS initialization moved to parameters<commit_after>#ifndef TRWS_INTERFACE_HXX_
#define TRWS_INTERFACE_HXX_
#include <opengm/inference/inference.hxx>
#include <opengm/inference/trws/trws_base.hxx>
#include <opengm/inference/trws/trws_reparametrization.hxx>

namespace opengm{

template<class GM>
struct TRWSi_Parameter : public trws_base::MaxSumTRWS_Parameters<typename GM::ValueType>
{
	typedef typename GM::ValueType ValueType;
	typedef trws_base::MaxSumTRWS_Parameters<ValueType> parent;
	typedef trws_base::DecompositionStorage<GM> Storage;
	typedef std::vector<typename GM::ValueType> DDVectorType;

	TRWSi_Parameter(size_t maxIternum=0,
			        typename Storage::StructureType decompositionType = Storage::GENERALSTRUCTURE,
			        ValueType precision=1.0,
			        bool absolutePrecision=true,
			        bool verbose=false)
	:parent(maxIternum,precision,absolutePrecision),
	 decompositionType_(decompositionType),
	 verbose_(verbose),
	 initPoint_(0)
{
}

	typename Storage::StructureType decompositionType_;
	bool verbose_;
	DDVectorType initPoint_;

	size_t& maxNumberOfIterations(){return parent::maxNumberOfIterations_;}
	const size_t& maxNumberOfIterations()const {return parent::maxNumberOfIterations_;}

	ValueType& precision(){return parent::precision_;}
	const ValueType& precision()const{return parent::precision_;}

	bool& isAbsolutePrecision(){return parent::absolutePrecision_;};//true for absolute precision, false for relative w.r.t. dual value
	const bool& isAbsolutePrecision()const{return parent::absolutePrecision_;};//true for absolute precision, false for relative w.r.t. dual value

	ValueType& minRelativeDualImprovement(){return parent::minRelativeDualImprovement_;}
	const ValueType& minRelativeDualImprovement()const{return parent::minRelativeDualImprovement_;}

	bool& fastComputations(){return parent::fastComputations_;}
	const bool& fastComputations()const{return parent::fastComputations_;}

	bool& canonicalNormalization(){return parent::canonicalNormalization_;};
	const bool& canonicalNormalization()const{return parent::canonicalNormalization_;};

	typename Storage::StructureType& decompositionType(){return decompositionType_;}
	const typename Storage::StructureType& decompositionType()const{return decompositionType_;}

	bool& verbose(){return verbose_;};
	const bool& verbose()const{return verbose_;};

#ifdef TRWS_DEBUG_OUTPUT
	  void print(std::ostream& fout)const
	  {
			fout << "maxNumberOfIterations="<<maxNumberOfIterations()<<std::endl;
			fout <<"precision="<<precision()<<std::endl;
			fout <<"isAbsolutePrecision="<<isAbsolutePrecision()<<std::endl;
			fout <<"minRelativeDualImprovement="<<minRelativeDualImprovement()<<std::endl;
			fout <<"fastComputations="<<fastComputations()<<std::endl;
			fout <<"canonicalNormalization="<<canonicalNormalization()<<std::endl;
			  if (decompositionType()==Storage::GENERALSTRUCTURE)
				  fout <<"decompositionType=" <<"GENERAL"<<std::endl;
			  else if (decompositionType()==Storage::GRIDSTRUCTURE)
				  fout <<"decompositionType=" <<"GRID"<<std::endl;
			  else
				  fout <<"decompositionType=" <<"UNKNOWN"<<std::endl;
			fout <<"verbose="<<verbose()<<std::endl;
			fout <<"treeAgreeMaxStableIter="<<parent::treeAgreeMaxStableIter_<<std::endl;
	  }
#endif
};

//! [class trwsi]
/// TRWSi - tree-reweighted sequential message passing
/// Based on the paper:
/// V. Kolmogorov
/// Convergent tree-reweighted message passing for energy minimization. IEEE Trans. on PAMI, 28(10):1568–1583, 2006.
///
/// it provides:
/// * primal integer approximate solution for MRF energy minimization problem
/// * lower bound for a solution of the problem.
///
///
/// TODO: Code can be significantly speeded up!
///
/// Corresponding author: Bogdan Savchynskyy
///
///\ingroup inference

template<class GM, class ACC>
class TRWSi : public Inference<GM, ACC>
{
public:
  typedef ACC AccumulationType;
  typedef GM GraphicalModelType;
  OPENGM_GM_TYPE_TYPEDEFS;
  typedef trws_base::MaxSumTRWS<GM, ACC> Solver;
  typedef trws_base::DecompositionStorage<GM> Storage;
  typedef visitors::ExplicitVerboseVisitor<TRWSi<GM, ACC> > VerboseVisitorType;
  typedef visitors::ExplicitTimingVisitor<TRWSi<GM, ACC> >  TimingVisitorType;
  typedef visitors::ExplicitEmptyVisitor< TRWSi<GM, ACC> >  EmptyVisitorType;

  typedef TRWSi_Parameter<GM> Parameter;
//  typedef typename Solver::ReparametrizerType ReparametrizerType;
  typedef TRWS_Reparametrizer<Storage,ACC> ReparametrizerType;
  typedef typename Storage::DDVectorType DDVectorType;

  TRWSi(const GraphicalModelType& gm, const Parameter& param
#ifdef TRWS_DEBUG_OUTPUT
		  ,std::ostream& fout=std::cout
#endif
  ):
						  _storage(gm,param.decompositionType_,(param.initPoint_.size()==0 ? 0 : &param.initPoint_)),
						  _solver(_storage,param
#ifdef TRWS_DEBUG_OUTPUT
								  ,(param.verbose_ ? fout : *OUT::nullstream::Instance()) //fout
#endif
						  ){
#ifdef TRWS_DEBUG_OUTPUT
	  std::ostream& out=(param.verbose_ ? fout : *OUT::nullstream::Instance());
	  out << "Parameters of the "<< name() <<" algorithm:"<<std::endl;
	  param.print(out);
#endif

	  if (param.maxNumberOfIterations_==0) throw
			  std::runtime_error("TRWSi: Maximal number of iterations (> 0) has to be specified!");
  }
  std::string name() const{ return "TRWSi"; }
  const GraphicalModelType& graphicalModel() const { return _storage.masterModel(); }
  InferenceTermination infer(){
	  _solver.infer();
	  return NORMAL;
  };

  template<class VISITOR> InferenceTermination infer(VISITOR & visitor){
	  trws_base::VisitorWrapper<VISITOR,TRWSi<GM, ACC> > visiwrap(&visitor,this);
	  _solver.infer(visiwrap);
	  return NORMAL;
  };

  InferenceTermination arg(std::vector<LabelType>& out, const size_t = 1) const
	  {
	  out = _solver.arg();
	  return opengm::NORMAL;}
  virtual ValueType bound() const{return _solver.bound();}
  virtual ValueType value() const{return _solver.value();}
  void getTreeAgreement(std::vector<bool>& out,std::vector<LabelType>* plabeling=0,std::vector<std::vector<LabelType> >* ptreeLabelings=0){_solver.getTreeAgreement(out,plabeling,ptreeLabelings);}
  //const Storage& getDecompositionStorage()const{return _storage;}
  Storage& getDecompositionStorage(){return _storage;}
  const typename Solver::FactorProperties& getFactorProperties()const {return _solver.getFactorProperties();}

//  ReparametrizerType* getReparametrizer(const typename ReparametrizerType::Parameter& params= typename ReparametrizerType::Parameter())const
//  {return _solver.getReparametrizer(params);}

  ReparametrizerType * getReparametrizer(const typename ReparametrizerType::Parameter& params=typename ReparametrizerType::Parameter())//const //TODO: make it constant
  {return new ReparametrizerType(_storage,_solver.getFactorProperties(),params);}

  void getDDVector(DDVectorType* pddvector)const{_storage.getDDVector(pddvector);}

  private:
   Storage _storage;
   Solver _solver;
};

}
#endif

<|endoftext|>


<commit_before>// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
//
// Copyright (c) 2006-2017, Knut Reinert, FU Berlin
// Copyright (c) 2016-2017, Knut Reinert & MPI Molekulare Genetik
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: David Heller <david.heller@fu-berlin.de>
// ==========================================================================
// Implementation of the biological dna5 alphabet.
// ==========================================================================

#pragma once

#include "../alphabet.hpp"

namespace seqan3
{
struct dna5
{
    using char_type = char;
    using integral_type = uint8_t;

    // strictly typed enum, unfortunately with scope
    enum struct c_type : integral_type
    {
        A,
        C,
        G,
        T,
        N,
        U = T,
        UNKNOWN = N
    };

    // import into local scope
    static constexpr c_type A{c_type::A};
    static constexpr c_type C{c_type::C};
    static constexpr c_type G{c_type::G};
    static constexpr c_type T{c_type::T};
    static constexpr c_type N{c_type::N};
    static constexpr c_type U{c_type::U};
    static constexpr c_type UNKNOWN{c_type::UNKNOWN};

    // the value
    c_type value;

    // implicit compatibility to inner_type
    constexpr dna5 & operator =(c_type const c)
    {
        value = c;
    }
    constexpr operator c_type() const
    {
        return value;
    }

    // explicit compatibility to char
    explicit constexpr operator char_type() const
    {
        return to_char();
    }
    constexpr char_type to_char() const
    {
        return value_to_char[static_cast<integral_type>(value)];
    }

    constexpr dna5 from_char(char_type const c)
    {
        value = char_to_value[c];
        return *this;
    }

    // explicit compatibility to integral
    constexpr integral_type to_integral() const
    {
        return static_cast<integral_type>(value);
    }

    constexpr dna5 from_integral(integral_type const c)
    {
        value = static_cast<c_type>(c);
        return *this;
    }

    // conversion tables
    static constexpr integral_type value_size{5};

    static constexpr char_type value_to_char[value_size]
    {
        'A',
        'C',
        'G',
        'T',
        'N'
    };

    static constexpr c_type char_to_value[256]
    {
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//4
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//29
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//54
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //A,             B,               C,               D,               E,
        c_type::A,       c_type::UNKNOWN, c_type::C,       c_type::UNKNOWN, c_type::UNKNOWN,
        //F,             G,               H,               I,               J,
        c_type::UNKNOWN, c_type::G,       c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //K,             L,               M,               N,               O,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::N,       c_type::UNKNOWN,//79
        // P,            Q,               R,               S,               T,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::T,
        //U,             V,               W,               X,               Y,
        c_type::T,       c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //Z
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //                                a,               b,               c,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::A,       c_type::UNKNOWN, c_type::C,
        //d,             e,               f,               g,               h,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::G,       c_type::UNKNOWN,//104
        //i,             j,               k,               l,               m,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //n,             o,               p,               q,               r,
        c_type::N,       c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //s,             t,               u,               v,               w,
        c_type::UNKNOWN, c_type::T,       c_type::T,       c_type::UNKNOWN, c_type::UNKNOWN,
        //x,             y,               z
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//129
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//154
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//179
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//204
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//229
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//254
        c_type::UNKNOWN
    };
};
} // namespace seqan3
<commit_msg>[FIX] reinsert static_assert for alphabet concept<commit_after>// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
//
// Copyright (c) 2006-2017, Knut Reinert, FU Berlin
// Copyright (c) 2016-2017, Knut Reinert & MPI Molekulare Genetik
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: David Heller <david.heller@fu-berlin.de>
// ==========================================================================
// Implementation of the biological dna5 alphabet.
// ==========================================================================

#pragma once

#include "../alphabet.hpp"

namespace seqan3
{
struct dna5
{
    using char_type = char;
    using integral_type = uint8_t;

    // strictly typed enum, unfortunately with scope
    enum struct c_type : integral_type
    {
        A,
        C,
        G,
        T,
        N,
        U = T,
        UNKNOWN = N
    };

    // import into local scope
    static constexpr c_type A{c_type::A};
    static constexpr c_type C{c_type::C};
    static constexpr c_type G{c_type::G};
    static constexpr c_type T{c_type::T};
    static constexpr c_type N{c_type::N};
    static constexpr c_type U{c_type::U};
    static constexpr c_type UNKNOWN{c_type::UNKNOWN};

    // the value
    c_type value;

    // implicit compatibility to inner_type
    constexpr dna5 & operator =(c_type const c)
    {
        value = c;
    }
    constexpr operator c_type() const
    {
        return value;
    }

    // explicit compatibility to char
    explicit constexpr operator char_type() const
    {
        return to_char();
    }
    constexpr char_type to_char() const
    {
        return value_to_char[static_cast<integral_type>(value)];
    }

    constexpr dna5 from_char(char_type const c)
    {
        value = char_to_value[c];
        return *this;
    }

    // explicit compatibility to integral
    constexpr integral_type to_integral() const
    {
        return static_cast<integral_type>(value);
    }

    constexpr dna5 from_integral(integral_type const c)
    {
        value = static_cast<c_type>(c);
        return *this;
    }

    // conversion tables
    static constexpr integral_type value_size{5};

    static constexpr char_type value_to_char[value_size]
    {
        'A',
        'C',
        'G',
        'T',
        'N'
    };

    static constexpr c_type char_to_value[256]
    {
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//4
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//29
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//54
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //A,             B,               C,               D,               E,
        c_type::A,       c_type::UNKNOWN, c_type::C,       c_type::UNKNOWN, c_type::UNKNOWN,
        //F,             G,               H,               I,               J,
        c_type::UNKNOWN, c_type::G,       c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //K,             L,               M,               N,               O,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::N,       c_type::UNKNOWN,//79
        // P,            Q,               R,               S,               T,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::T,
        //U,             V,               W,               X,               Y,
        c_type::T,       c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //Z
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //                                a,               b,               c,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::A,       c_type::UNKNOWN, c_type::C,
        //d,             e,               f,               g,               h,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::G,       c_type::UNKNOWN,//104
        //i,             j,               k,               l,               m,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //n,             o,               p,               q,               r,
        c_type::N,       c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        //s,             t,               u,               v,               w,
        c_type::UNKNOWN, c_type::T,       c_type::T,       c_type::UNKNOWN, c_type::UNKNOWN,
        //x,             y,               z
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//129
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//154
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//179
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//204
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//229
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,
        c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN, c_type::UNKNOWN,//254
        c_type::UNKNOWN
    };
};

// shall fulfill Alphabet concept
static_assert(alphabet_concept<dna5>);

} // namespace seqan3
<|endoftext|>


<commit_before>//  (C) Copyright Gennadiy Rozental 2005-2014.
//  Use, modification, and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org/libs/test for the library home page.
//
//  File        : $RCSfile$
//
//  Version     : $Revision$
//
//  Description : flexible configuration file iterator definition
// ***************************************************************************

#ifndef BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER
#define BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER

// Boost.Runtime.Parameter
#include <boost/test/utils/runtime/config.hpp>

#include <boost/test/utils/runtime/fwd.hpp>

// Boost.Test
#include <boost/test/utils/iterator/input_iterator_facade.hpp>
#include <boost/test/utils/named_params.hpp>

// Boost
#include <boost/shared_ptr.hpp>

namespace boost {

namespace BOOST_RT_PARAM_NAMESPACE {

namespace file {

// Public typedef
typedef std::pair<dstring,long> location;

// ************************************************************************** //
// **************                   modifiers                  ************** //
// ************************************************************************** //

namespace cfg_detail {
    struct path_separators_t;
    struct line_delimeter_t;
    struct sl_comment_delimeter_t;
    struct command_delimeter_t;
    struct line_beak_t;
    struct macro_ref_begin_t;
    struct macro_ref_end_t;
    struct include_kw_t;
    struct define_kw_t;
    struct undef_kw_t;
    struct ifdef_kw_t;
    struct ifndef_kw_t;
    struct else_kw_t;
    struct endif_kw_t;

    struct buffer_size_t;

    struct trim_leading_spaces_t;
    struct trim_trailing_spaces_t;
    struct skip_empty_lines_t;
    struct detect_missing_macro_t;
} // namespace cfg_detail

namespace {

nfp::typed_keyword<cstring,cfg_detail::path_separators_t>       path_separators;
nfp::typed_keyword<char_type ,cfg_detail::line_delimeter_t>     line_delimeter;
nfp::typed_keyword<cstring,cfg_detail::sl_comment_delimeter_t>  single_line_comment_delimeter;
nfp::typed_keyword<cstring,cfg_detail::command_delimeter_t>     command_delimeter;
nfp::typed_keyword<cstring,cfg_detail::line_beak_t>             line_beak;
nfp::typed_keyword<cstring,cfg_detail::macro_ref_begin_t>       macro_ref_begin;
nfp::typed_keyword<cstring,cfg_detail::macro_ref_end_t>         macro_ref_end;
nfp::typed_keyword<cstring,cfg_detail::include_kw_t>            include_kw;
nfp::typed_keyword<cstring,cfg_detail::define_kw_t>             define_kw;
nfp::typed_keyword<cstring,cfg_detail::undef_kw_t>              undef_kw;
nfp::typed_keyword<cstring,cfg_detail::ifdef_kw_t>              ifdef_kw;
nfp::typed_keyword<cstring,cfg_detail::ifndef_kw_t>             ifndef_kw;
nfp::typed_keyword<cstring,cfg_detail::else_kw_t>               else_kw;
nfp::typed_keyword<cstring,cfg_detail::endif_kw_t>              endif_kw;

nfp::typed_keyword<std::size_t,cfg_detail::buffer_size_t>       buffer_size;

nfp::typed_keyword<bool,cfg_detail::trim_leading_spaces_t>      trim_leading_spaces;
nfp::typed_keyword<bool,cfg_detail::trim_trailing_spaces_t>     trim_trailing_spaces;
nfp::typed_keyword<bool,cfg_detail::skip_empty_lines_t>         skip_empty_lines;
nfp::typed_keyword<bool,cfg_detail::detect_missing_macro_t>     detect_missing_macro;

} // local namespace

// ************************************************************************** //
// **************      runtime::file::config_file_iterator      ************** //
// ************************************************************************** //

class config_file_iterator : public unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> {
    typedef unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> base;
public:
    // Public typedefs
    typedef boost::function<cstring ()>   command_handler;

    // Constructors
                    config_file_iterator() {}
    explicit        config_file_iterator( cstring file_name )
    {
        construct();
        load( file_name );
    }
    template<typename Modifiers>
                    config_file_iterator( cstring file_name, Modifiers const& m )
    {
        construct();
        m.apply_to( *this );
        load( file_name );
    }
    config_file_iterator( config_file_iterator const& rhs )
    : base( rhs )
    , m_pimpl( rhs.m_pimpl )
    {
        rhs.m_valid = false;
    }

    void operator=( config_file_iterator const& rhs )
    {
        if( this == &rhs )
            return;

        (base&)(*this)  = rhs;
        m_pimpl         = rhs.m_pimpl;
        rhs.m_valid     = false;
    }    // Assignment

    // Access methods
    location const& curr_location();
    void            register_command_handler( cstring command_kw, command_handler const& );

    // Parameters setters
    void            set_parameter( rtti::id_t, cstring );
    void            set_parameter( rtti::id_t, bool );
    void            set_parameter( rtti::id_t, char_type );
    void            set_parameter( rtti::id_t, std::size_t );

private:
    friend class unit_test::input_iterator_core_access;

    void            construct();
    void            load( cstring file_name );

    // increment implementation
    bool            get();

    // Data members
    struct Impl;
    shared_ptr<Impl> m_pimpl;
};

} // namespace file

} // namespace BOOST_RT_PARAM_NAMESPACE

} // namespace boost

#endif // BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER
<commit_msg>fixed compilation issue on mac<commit_after>//  (C) Copyright Gennadiy Rozental 2005-2014.
//  Use, modification, and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org/libs/test for the library home page.
//
//  File        : $RCSfile$
//
//  Version     : $Revision$
//
//  Description : flexible configuration file iterator definition
// ***************************************************************************

#ifndef BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER
#define BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER

// Boost.Runtime.Parameter
#include <boost/test/utils/runtime/config.hpp>

#include <boost/test/utils/runtime/fwd.hpp>

// Boost.Test
#include <boost/test/utils/iterator/input_iterator_facade.hpp>
#include <boost/test/utils/named_params.hpp>

// Boost
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>

namespace boost {

namespace BOOST_RT_PARAM_NAMESPACE {

namespace file {

// Public typedef
typedef std::pair<dstring,long> location;

// ************************************************************************** //
// **************                   modifiers                  ************** //
// ************************************************************************** //

namespace cfg_detail {
    struct path_separators_t;
    struct line_delimeter_t;
    struct sl_comment_delimeter_t;
    struct command_delimeter_t;
    struct line_beak_t;
    struct macro_ref_begin_t;
    struct macro_ref_end_t;
    struct include_kw_t;
    struct define_kw_t;
    struct undef_kw_t;
    struct ifdef_kw_t;
    struct ifndef_kw_t;
    struct else_kw_t;
    struct endif_kw_t;

    struct buffer_size_t;

    struct trim_leading_spaces_t;
    struct trim_trailing_spaces_t;
    struct skip_empty_lines_t;
    struct detect_missing_macro_t;
} // namespace cfg_detail

namespace {

nfp::typed_keyword<cstring,cfg_detail::path_separators_t>       path_separators;
nfp::typed_keyword<char_type ,cfg_detail::line_delimeter_t>     line_delimeter;
nfp::typed_keyword<cstring,cfg_detail::sl_comment_delimeter_t>  single_line_comment_delimeter;
nfp::typed_keyword<cstring,cfg_detail::command_delimeter_t>     command_delimeter;
nfp::typed_keyword<cstring,cfg_detail::line_beak_t>             line_beak;
nfp::typed_keyword<cstring,cfg_detail::macro_ref_begin_t>       macro_ref_begin;
nfp::typed_keyword<cstring,cfg_detail::macro_ref_end_t>         macro_ref_end;
nfp::typed_keyword<cstring,cfg_detail::include_kw_t>            include_kw;
nfp::typed_keyword<cstring,cfg_detail::define_kw_t>             define_kw;
nfp::typed_keyword<cstring,cfg_detail::undef_kw_t>              undef_kw;
nfp::typed_keyword<cstring,cfg_detail::ifdef_kw_t>              ifdef_kw;
nfp::typed_keyword<cstring,cfg_detail::ifndef_kw_t>             ifndef_kw;
nfp::typed_keyword<cstring,cfg_detail::else_kw_t>               else_kw;
nfp::typed_keyword<cstring,cfg_detail::endif_kw_t>              endif_kw;

nfp::typed_keyword<std::size_t,cfg_detail::buffer_size_t>       buffer_size;

nfp::typed_keyword<bool,cfg_detail::trim_leading_spaces_t>      trim_leading_spaces;
nfp::typed_keyword<bool,cfg_detail::trim_trailing_spaces_t>     trim_trailing_spaces;
nfp::typed_keyword<bool,cfg_detail::skip_empty_lines_t>         skip_empty_lines;
nfp::typed_keyword<bool,cfg_detail::detect_missing_macro_t>     detect_missing_macro;

} // local namespace

// ************************************************************************** //
// **************      runtime::file::config_file_iterator      ************** //
// ************************************************************************** //

class config_file_iterator : public unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> {
    typedef unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> base;
public:
    // Public typedefs
    typedef boost::function<void (cstring)>   command_handler;

    // Constructors
                    config_file_iterator() {}
    explicit        config_file_iterator( cstring file_name )
    {
        construct();
        load( file_name );
    }
    template<typename Modifiers>
                    config_file_iterator( cstring file_name, Modifiers const& m )
    {
        construct();
        m.apply_to( *this );
        load( file_name );
    }
    config_file_iterator( config_file_iterator const& rhs )
    : base( rhs )
    , m_pimpl( rhs.m_pimpl )
    {
        rhs.m_valid = false;
    }

    void operator=( config_file_iterator const& rhs )
    {
        if( this == &rhs )
            return;

        (base&)(*this)  = rhs;
        m_pimpl         = rhs.m_pimpl;
        rhs.m_valid     = false;
    }    // Assignment

    // Access methods
    location const& curr_location();
    void            register_command_handler( cstring command_kw, command_handler const& );

    // Parameters setters
    void            set_parameter( rtti::id_t, cstring );
    void            set_parameter( rtti::id_t, bool );
    void            set_parameter( rtti::id_t, char_type );
    void            set_parameter( rtti::id_t, std::size_t );

private:
    friend class unit_test::input_iterator_core_access;

    void            construct();
    void            load( cstring file_name );

    // increment implementation
    bool            get();

    // Data members
    struct Impl;
    shared_ptr<Impl> m_pimpl;
};

} // namespace file

} // namespace BOOST_RT_PARAM_NAMESPACE

} // namespace boost

#endif // BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER
<|endoftext|>


<commit_before>/**
 Copyright 2015 Joachim Wolff
 Master Thesis
 Tutors: Milad Miladi, Fabrizio Costa
 Winter semester 2015/2016

 Chair of Bioinformatics
 Department of Computer Science
 Faculty of Engineering
 Albert-Ludwig-University Freiburg im Breisgau
**/
#include <Python.h>

#include "../minHash.h"
#include "../parsePythonToCpp.h"

static neighborhood* neighborhoodComputation(size_t pMinHashAddress, PyObject* pInstancesListObj,PyObject* pFeaturesListObj,PyObject* pDataListObj,
                                                   size_t pMaxNumberOfInstances, size_t pMaxNumberOfFeatures,
                                                   size_t pNneighbors, int pFast) {
    std::cout << "20" << std::endl;

    SparseMatrixFloat* originalDataMatrix = parseRawData(pInstancesListObj, pFeaturesListObj, pDataListObj,
                                                    pMaxNumberOfInstances, pMaxNumberOfFeatures);
    std::cout << "24" << std::endl;

    MinHash* minHash = reinterpret_cast<MinHash* >(pMinHashAddress);
    std::cout << "27" << std::endl;

    // compute the k-nearest neighbors
    return minHash->kneighbors(originalDataMatrix, pNneighbors, pFast);
}

static neighborhood* fitNeighborhoodComputation(size_t pMinHashAddress, PyObject* pInstancesListObj,PyObject* pFeaturesListObj,PyObject* pDataListObj,
                                                   size_t pMaxNumberOfInstances, size_t pMaxNumberOfFeatures,
                                                   size_t pNneighbors, int pFast) {
    SparseMatrixFloat* originalDataMatrix = parseRawData(pInstancesListObj, pFeaturesListObj, pDataListObj,
                                                    pMaxNumberOfInstances, pMaxNumberOfFeatures);
    // get pointer to the minhash object
    MinHash* minHash = reinterpret_cast<MinHash* >(pMinHashAddress);
    minHash->set_mOriginalData(originalDataMatrix);

    minHash->fit(originalDataMatrix);
    SparseMatrixFloat* emptyMatrix = new SparseMatrixFloat(0, 0);
    neighborhood* neighborhood_ = minHash->kneighbors(emptyMatrix, pNneighbors, pFast);
    delete emptyMatrix;
    return neighborhood_;
}

static PyObject* createObject(PyObject* self, PyObject* args) {
    size_t numberOfHashFunctions, blockSize, numberOfCores, chunkSize,
    nNeighbors, minimalBlocksInCommon, maxBinSize,
    maximalNumberOfHashCollisions, excessFactor;
    int fast;

    if (!PyArg_ParseTuple(args, "kkkkkkkkki", &numberOfHashFunctions,
                        &blockSize, &numberOfCores, &chunkSize, &nNeighbors,
                        &minimalBlocksInCommon, &maxBinSize,
                        &maximalNumberOfHashCollisions, &excessFactor, &fast))
        return NULL;
    MinHash* minHash = new MinHash (numberOfHashFunctions, blockSize, numberOfCores, chunkSize,
                    maxBinSize, nNeighbors, minimalBlocksInCommon,
                    excessFactor, maximalNumberOfHashCollisions, fast);

    size_t adressMinHashObject = reinterpret_cast<size_t>(minHash);
    PyObject* pointerToInverseIndex = Py_BuildValue("k", adressMinHashObject);
    return pointerToInverseIndex;
}
static PyObject* deleteObject(PyObject* self, PyObject* args) {
    size_t addressMinHashObject;

    if (!PyArg_ParseTuple(args, "k", &addressMinHashObject))
        return Py_BuildValue("i", 1);;

    MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
    delete minHash;
    return Py_BuildValue("i", 0);
}

static PyObject* fit(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkk",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &addressMinHashObject))
        return NULL;
    std::cout << "86" << std::endl;
    // parse from python list to a c++ map<size_t, vector<size_t> >
    // where key == instance id and vector<size_t> == non null feature ids
    SparseMatrixFloat* originalDataMatrix = parseRawData(instancesListObj, featuresListObj, dataListObj,
                                                    maxNumberOfInstances, maxNumberOfFeatures);
    std::cout << "91" << std::endl;

    // get pointer to the minhash object
    // std::cout << "94" << std::endl;

    MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
    minHash->set_mOriginalData(originalDataMatrix);
    std::cout << "98" << std::endl;

    minHash->fit(originalDataMatrix);
    std::cout << "101" << std::endl;

    addressMinHashObject = reinterpret_cast<size_t>(minHash);
    PyObject * pointerToInverseIndex = Py_BuildValue("k", addressMinHashObject);
    return pointerToInverseIndex;
}
static PyObject* partialFit(PyObject* self, PyObject* args) {
    return fit(self, args);
}
static PyObject* kneighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, nNeighbors, maxNumberOfInstances,
            maxNumberOfFeatures, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &nNeighbors, &returnDistance,
                        &fast, &addressMinHashObject))
        return NULL;
    std::cout << "125" << std::endl;

    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    std::cout << "130" << std::endl;

    size_t cutFirstValue = 0;
    if (PyList_Size(instancesListObj) == 0) {
        cutFirstValue = 1;
    }
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    std::cout << "140" << std::endl;

    return bringNeighborhoodInShape(neighborhood_, nNeighbors, cutFirstValue, returnDistance);
}

static PyObject* kneighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, nNeighbors, maxNumberOfInstances,
            maxNumberOfFeatures, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &nNeighbors, &returnDistance,
                        &fast, &addressMinHashObject))
        return NULL;
    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    return buildGraph(neighborhood_, nNeighbors, returnDistance);
}
static PyObject* radiusNeighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, radius, maxNumberOfInstances,
             maxNumberOfFeatures, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &radius, &returnDistance,
                        &fast, &addressMinHashObject))
        return NULL;
    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    size_t cutFirstValue = 0;
    if (PyList_Size(instancesListObj) == 0) {
        cutFirstValue = 1;
    }
    return radiusNeighborhood(neighborhood_, radius, cutFirstValue, returnDistance);
}
static PyObject* radiusNeighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, radius, maxNumberOfInstances,
            maxNumberOfFeatures, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &radius, &returnDistance,
                        &fast, &addressMinHashObject))
        return NULL;
    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    return radiusNeighborhoodGraph(neighborhood_, radius, returnDistance);
}
static PyObject* fitKneighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            nNeighbors, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &nNeighbors,
                            &returnDistance, &fast,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    size_t cutFirstValue = 1;
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    return bringNeighborhoodInShape(neighborhood_, nNeighbors, cutFirstValue, returnDistance);
}
static PyObject* fitKneighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            nNeighbors, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkik",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &nNeighbors,
                            &returnDistance, &fast,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    return buildGraph(neighborhood_, nNeighbors, returnDistance);

}
static PyObject* fitRadiusNeighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            radius, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &radius, &returnDistance,
                            &fast,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    size_t cutFirstValue = 1;
    return radiusNeighborhood(neighborhood_, radius, cutFirstValue, returnDistance);
}
static PyObject* fitRadiusNeighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            radius, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &radius, &returnDistance, &fast,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    return radiusNeighborhoodGraph(neighborhood_, radius, returnDistance);
}
// definition of avaible functions for python and which function parsing fucntion in c++ should be called.
static PyMethodDef minHashFunctions[] = {
    {"fit", fit, METH_VARARGS, "Calculate the inverse index for the given instances."},
    {"partial_fit", partialFit, METH_VARARGS, "Extend the inverse index with the given instances."},
    {"kneighbors", kneighbors, METH_VARARGS, "Calculate k-nearest neighbors."},
    {"kneighbors_graph", kneighborsGraph, METH_VARARGS, "Calculate k-nearest neighbors as a graph."},
    {"radius_neighbors", radiusNeighbors, METH_VARARGS, "Calculate the neighbors inside a given radius."},
    {"radius_neighbors_graph", radiusNeighborsGraph, METH_VARARGS, "Calculate the neighbors inside a given radius as a graph."},
    {"fit_kneighbors", fitKneighbors, METH_VARARGS, "Fits and calculates k-nearest neighbors."},
    {"fit_kneighbors_graph", fitKneighborsGraph, METH_VARARGS, "Fits and calculates k-nearest neighbors as a graph."},
    {"fit_radius_neighbors", fitRadiusNeighbors, METH_VARARGS, "Fits and calculates the neighbors inside a given radius."},
    {"fit_radius_neighbors_graph", fitRadiusNeighborsGraph, METH_VARARGS, "Fits and calculates the neighbors inside a given radius as a graph."},
    {"create_object", createObject, METH_VARARGS, "Create the c++ object."},
    {"delete_object", deleteObject, METH_VARARGS, "Delete the c++ object by calling the destructor."},
    {NULL, NULL, 0, NULL}
};

// definition of the module for python
PyMODINIT_FUNC
init_minHash(void)
{
    (void) Py_InitModule("_minHash", minHashFunctions);
}<commit_msg>Added symmetric option for graph outputs<commit_after>/**
 Copyright 2015 Joachim Wolff
 Master Thesis
 Tutors: Milad Miladi, Fabrizio Costa
 Winter semester 2015/2016

 Chair of Bioinformatics
 Department of Computer Science
 Faculty of Engineering
 Albert-Ludwig-University Freiburg im Breisgau
**/
#include <Python.h>

#include "../minHash.h"
#include "../parsePythonToCpp.h"

static neighborhood* neighborhoodComputation(size_t pMinHashAddress, PyObject* pInstancesListObj,PyObject* pFeaturesListObj,PyObject* pDataListObj,
                                                   size_t pMaxNumberOfInstances, size_t pMaxNumberOfFeatures,
                                                   size_t pNneighbors, int pFast) {
    // std::cout << "20" << std::endl;

    SparseMatrixFloat* originalDataMatrix = parseRawData(pInstancesListObj, pFeaturesListObj, pDataListObj,
                                                    pMaxNumberOfInstances, pMaxNumberOfFeatures);
    // std::cout << "24" << std::endl;

    MinHash* minHash = reinterpret_cast<MinHash* >(pMinHashAddress);
    // std::cout << "27" << std::endl;

    // compute the k-nearest neighbors
    return minHash->kneighbors(originalDataMatrix, pNneighbors, pFast);
}

static neighborhood* fitNeighborhoodComputation(size_t pMinHashAddress, PyObject* pInstancesListObj,PyObject* pFeaturesListObj,PyObject* pDataListObj,
                                                   size_t pMaxNumberOfInstances, size_t pMaxNumberOfFeatures,
                                                   size_t pNneighbors, int pFast) {
    SparseMatrixFloat* originalDataMatrix = parseRawData(pInstancesListObj, pFeaturesListObj, pDataListObj,
                                                    pMaxNumberOfInstances, pMaxNumberOfFeatures);
    // get pointer to the minhash object
    MinHash* minHash = reinterpret_cast<MinHash* >(pMinHashAddress);
    minHash->set_mOriginalData(originalDataMatrix);

    minHash->fit(originalDataMatrix);
    SparseMatrixFloat* emptyMatrix = new SparseMatrixFloat(0, 0);
    neighborhood* neighborhood_ = minHash->kneighbors(emptyMatrix, pNneighbors, pFast);
    delete emptyMatrix;
    return neighborhood_;
}

static PyObject* createObject(PyObject* self, PyObject* args) {
    size_t numberOfHashFunctions, blockSize, numberOfCores, chunkSize,
    nNeighbors, minimalBlocksInCommon, maxBinSize,
    maximalNumberOfHashCollisions, excessFactor;
    int fast;

    if (!PyArg_ParseTuple(args, "kkkkkkkkki", &numberOfHashFunctions,
                        &blockSize, &numberOfCores, &chunkSize, &nNeighbors,
                        &minimalBlocksInCommon, &maxBinSize,
                        &maximalNumberOfHashCollisions, &excessFactor, &fast))
        return NULL;
    MinHash* minHash = new MinHash (numberOfHashFunctions, blockSize, numberOfCores, chunkSize,
                    maxBinSize, nNeighbors, minimalBlocksInCommon,
                    excessFactor, maximalNumberOfHashCollisions, fast);

    size_t adressMinHashObject = reinterpret_cast<size_t>(minHash);
    PyObject* pointerToInverseIndex = Py_BuildValue("k", adressMinHashObject);
    return pointerToInverseIndex;
}
static PyObject* deleteObject(PyObject* self, PyObject* args) {
    size_t addressMinHashObject;

    if (!PyArg_ParseTuple(args, "k", &addressMinHashObject))
        return Py_BuildValue("i", 1);;

    MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
    delete minHash;
    return Py_BuildValue("i", 0);
}

static PyObject* fit(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkk",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &addressMinHashObject))
        return NULL;
    // std::cout << "86" << std::endl;
    // parse from python list to a c++ map<size_t, vector<size_t> >
    // where key == instance id and vector<size_t> == non null feature ids
    SparseMatrixFloat* originalDataMatrix = parseRawData(instancesListObj, featuresListObj, dataListObj,
                                                    maxNumberOfInstances, maxNumberOfFeatures);
    // std::cout << "91" << std::endl;

    // get pointer to the minhash object
    // std::cout << "94" << std::endl;

    MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
    minHash->set_mOriginalData(originalDataMatrix);
    // std::cout << "98" << std::endl;

    minHash->fit(originalDataMatrix);
    // std::cout << "101" << std::endl;

    addressMinHashObject = reinterpret_cast<size_t>(minHash);
    PyObject * pointerToInverseIndex = Py_BuildValue("k", addressMinHashObject);
    return pointerToInverseIndex;
}
static PyObject* partialFit(PyObject* self, PyObject* args) {
    return fit(self, args);
}
static PyObject* kneighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, nNeighbors, maxNumberOfInstances,
            maxNumberOfFeatures, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &nNeighbors, &returnDistance,
                        &fast, &addressMinHashObject))
        return NULL;
    // std::cout << "125" << std::endl;

    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    // std::cout << "130" << std::endl;

    size_t cutFirstValue = 0;
    if (PyList_Size(instancesListObj) == 0) {
        cutFirstValue = 1;
    }
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    // std::cout << "140" << std::endl;

    return bringNeighborhoodInShape(neighborhood_, nNeighbors, cutFirstValue, returnDistance);
}

static PyObject* kneighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, nNeighbors, maxNumberOfInstances,
            maxNumberOfFeatures, returnDistance, symmetric;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkikk",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &nNeighbors, &returnDistance,
                        &fast, &symmetric, &addressMinHashObject))
        return NULL;
    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    return buildGraph(neighborhood_, nNeighbors, returnDistance, symmetric);
}
static PyObject* radiusNeighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, radius, maxNumberOfInstances,
             maxNumberOfFeatures, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &radius, &returnDistance,
                        &fast, &addressMinHashObject))
        return NULL;
    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    size_t cutFirstValue = 0;
    if (PyList_Size(instancesListObj) == 0) {
        cutFirstValue = 1;
    }
    return radiusNeighborhood(neighborhood_, radius, cutFirstValue, returnDistance);
}
static PyObject* radiusNeighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, radius, maxNumberOfInstances,
            maxNumberOfFeatures, returnDistance, symmetric;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkikk",
                        &PyList_Type, &instancesListObj,
                        &PyList_Type, &featuresListObj,
                        &PyList_Type, &dataListObj,
                        &maxNumberOfInstances,
                        &maxNumberOfFeatures,
                        &radius, &returnDistance,
                        &fast, &symmetric, &addressMinHashObject))
        return NULL;
    // compute the k-nearest neighbors
    neighborhood* neighborhood_ = neighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    return radiusNeighborhoodGraph(neighborhood_, radius, returnDistance, symmetric);
}
static PyObject* fitKneighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            nNeighbors, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &nNeighbors,
                            &returnDistance, &fast,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    size_t cutFirstValue = 1;
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    return bringNeighborhoodInShape(neighborhood_, nNeighbors, cutFirstValue, returnDistance);
}
static PyObject* fitKneighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            nNeighbors, returnDistance, symmetric;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkikk",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &nNeighbors,
                            &returnDistance, &fast, &symmetric,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, nNeighbors, fast);
    if (nNeighbors == 0) {
        MinHash* minHash = reinterpret_cast<MinHash* >(addressMinHashObject);
        nNeighbors = minHash->getNneighbors();
    }
    return buildGraph(neighborhood_, nNeighbors, returnDistance, symmetric);

}
static PyObject* fitRadiusNeighbors(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            radius, returnDistance;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkik",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &radius, &returnDistance,
                            &fast,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    size_t cutFirstValue = 1;
    return radiusNeighborhood(neighborhood_, radius, cutFirstValue, returnDistance);
}
static PyObject* fitRadiusNeighborsGraph(PyObject* self, PyObject* args) {
    size_t addressMinHashObject, maxNumberOfInstances, maxNumberOfFeatures,
            radius, returnDistance, symmetric;
    int fast;
    PyObject* instancesListObj, *featuresListObj, *dataListObj;

    if (!PyArg_ParseTuple(args, "O!O!O!kkkkikk",
                            &PyList_Type, &instancesListObj,
                            &PyList_Type, &featuresListObj,
                            &PyList_Type, &dataListObj,
                            &maxNumberOfInstances,
                            &maxNumberOfFeatures,
                            &radius, &returnDistance, &fast,
                            &symmetric,
                            &addressMinHashObject))
        return NULL;

    neighborhood* neighborhood_ = fitNeighborhoodComputation(addressMinHashObject, instancesListObj, featuresListObj, dataListObj,
                                                   maxNumberOfInstances, maxNumberOfFeatures, MAX_VALUE, fast);
    return radiusNeighborhoodGraph(neighborhood_, radius, returnDistance, symmetric);
}
// definition of avaible functions for python and which function parsing fucntion in c++ should be called.
static PyMethodDef minHashFunctions[] = {
    {"fit", fit, METH_VARARGS, "Calculate the inverse index for the given instances."},
    {"partial_fit", partialFit, METH_VARARGS, "Extend the inverse index with the given instances."},
    {"kneighbors", kneighbors, METH_VARARGS, "Calculate k-nearest neighbors."},
    {"kneighbors_graph", kneighborsGraph, METH_VARARGS, "Calculate k-nearest neighbors as a graph."},
    {"radius_neighbors", radiusNeighbors, METH_VARARGS, "Calculate the neighbors inside a given radius."},
    {"radius_neighbors_graph", radiusNeighborsGraph, METH_VARARGS, "Calculate the neighbors inside a given radius as a graph."},
    {"fit_kneighbors", fitKneighbors, METH_VARARGS, "Fits and calculates k-nearest neighbors."},
    {"fit_kneighbors_graph", fitKneighborsGraph, METH_VARARGS, "Fits and calculates k-nearest neighbors as a graph."},
    {"fit_radius_neighbors", fitRadiusNeighbors, METH_VARARGS, "Fits and calculates the neighbors inside a given radius."},
    {"fit_radius_neighbors_graph", fitRadiusNeighborsGraph, METH_VARARGS, "Fits and calculates the neighbors inside a given radius as a graph."},
    {"create_object", createObject, METH_VARARGS, "Create the c++ object."},
    {"delete_object", deleteObject, METH_VARARGS, "Delete the c++ object by calling the destructor."},
    {NULL, NULL, 0, NULL}
};

// definition of the module for python
PyMODINIT_FUNC
init_minHash(void)
{
    (void) Py_InitModule("_minHash", minHashFunctions);
}<|endoftext|>