<commit_before>/*
 * Copyright 2010,
 * <NAME>,
 * <NAME>,
 *
 * CNRS/AIST
 *
 * This file is part of sot-core.
 * sot-core is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 * sot-core is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.  You should
 * have received a copy of the GNU Lesser General Public License along
 * with sot-core.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __SOT_FIRFILTER_HH__
#define __SOT_FIRFILTER_HH__

#include <cassert>

#include <vector>
#include <algorithm>
#include <iterator>

#include <dynamic-graph/entity.h>
#include <dynamic-graph/all-signals.h>
#include <dynamic-graph/command-setter.h>
#include <dynamic-graph/command-getter.h>

namespace dg = dynamicgraph;

namespace dynamicgraph {
  namespace sot {

    namespace detail
    {
      // GRMBL boost-sandox::circular_buffer smells... Why keep using 1.33?!
      // As a workaround, only the part of circular_buffer's interface used
      // here is implemented.
      // Ugly, fatty piece of code.
      template<class T>
      class circular_buffer
      {
      public:
	circular_buffer(): buf(1), start(0), numel(0) {}
	void push_front(const T& data) {
	  if(start){ --start; } else { start = buf.size()-1; }
	  buf[start] = data;
	  if(numel < buf.size()){ ++numel; }
	}
	void reset_capacity(size_t n) {
	  buf.resize(n);
	  start = 0;
	  numel = 0;
	}
	void reset_capacity(size_t n, const T& el) {
	  buf.clear();
	  buf.resize(n, el);
	  start = 0;
	  numel = 0;
	}
	T& operator[](size_t i) {
	  assert((i<numel) && "Youre accessing an empty buffer");
	  size_t index = (start+i) % buf.size();
	  return buf[index];
	}
	size_t size() const { return numel; }
      private:
	std::vector<T> buf;
	size_t start;
	size_t numel;
      }; // class circular_buffer
    } // namespace detail

    template<class sigT, class coefT> class FIRFilter;

    namespace command {
      using ::dynamicgraph::command::Command;
      using ::dynamicgraph::command::Value;
      
      template <class sigT, class coefT>
      class SetElement : public Command
      {
      public:
    	SetElement (FIRFilter < sigT, coefT > & entity,
		    const std::string& docstring);
	Value doExecute ();
      }; // class SetElement

      template <class sigT, class coefT>
      class GetElement : public Command
      {
      public:
    	GetElement (FIRFilter < sigT, coefT > & entity,
		    const std::string& docstring);
	Value doExecute ();
      }; // class SetElement
    } // namespace command
    
    using ::dynamicgraph::command::Setter;
    using ::dynamicgraph::command::Getter;

    template < class sigT, class coefT >
    class FIRFilter
      : public Entity
    {
    public:
      virtual const std::string& getClassName() const
      {
	return Entity::getClassName();
      }
      static std::string getTypeName( void )
      {
	return "Unknown";
      }
      static const std::string CLASS_NAME;
      
      std::string getDocString () const
      {
	return
	  "Finite impulse response filter\n"
	  "\n"
	  "  Provide the following sum in output signal:\n"
	  "             N                   \n"
	  "             __                  \n"
	  "     y (n) = \\   c  s (n-i)      \n"
	  "             /_   i              \n"
	  "             i=0                 \n"
	  "                                 \n"
	  "  where\n"
	  "    -  c_i are coefficients stored in an array\n"
	  "    -  N is the size of the array\n"
	  "    -  s is the input signal.\n";
      }
    public:
      FIRFilter( const std::string& name )
	: Entity(name)
	, SIN(NULL,"sotFIRFilter("+name+")::input(T)::in")
	, SOUT(boost::bind(&FIRFilter::compute,this,_1,_2),
	       SIN,
	       "sotFIRFilter("+name+")::output(T)::out")
      {
	signalRegistration( SIN<<SOUT );
	std::string docstring =
	  "  Set element at rank in array of coefficients\n"
	  "\n"
	  "    Input:\n"
	  "      - positive int: rank\n"
	  "      - element\n";
	addCommand ("setElement",
		    new command::SetElement <sigT, coefT>
		    (*this, docstring));<commit_msg>Rename FIRFilter signals to fix syntax error in python<commit_after>/*
 * Copyright 2010,
 * <NAME>,
 * <NAME>,
 *
 * CNRS/AIST
 *
 * This file is part of sot-core.
 * sot-core is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 * sot-core is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.  You should
 * have received a copy of the GNU Lesser General Public License along
 * with sot-core.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __SOT_FIRFILTER_HH__
#define __SOT_FIRFILTER_HH__

#include <cassert>

#include <vector>
#include <algorithm>
#include <iterator>

#include <dynamic-graph/entity.h>
#include <dynamic-graph/all-signals.h>
#include <dynamic-graph/command-setter.h>
#include <dynamic-graph/command-getter.h>

namespace dg = dynamicgraph;

namespace dynamicgraph {
  namespace sot {

    namespace detail
    {
      // GRMBL boost-sandox::circular_buffer smells... Why keep using 1.33?!
      // As a workaround, only the part of circular_buffer's interface used
      // here is implemented.
      // Ugly, fatty piece of code.
      template<class T>
      class circular_buffer
      {
      public:
	circular_buffer(): buf(1), start(0), numel(0) {}
	void push_front(const T& data) {
	  if(start){ --start; } else { start = buf.size()-1; }
	  buf[start] = data;
	  if(numel < buf.size()){ ++numel; }
	}
	void reset_capacity(size_t n) {
	  buf.resize(n);
	  start = 0;
	  numel = 0;
	}
	void reset_capacity(size_t n, const T& el) {
	  buf.clear();
	  buf.resize(n, el);
	  start = 0;
	  numel = 0;
	}
	T& operator[](size_t i) {
	  assert((i<numel) && "Youre accessing an empty buffer");
	  size_t index = (start+i) % buf.size();
	  return buf[index];
	}
	size_t size() const { return numel; }
      private:
	std::vector<T> buf;
	size_t start;
	size_t numel;
      }; // class circular_buffer
    } // namespace detail

    template<class sigT, class coefT> class FIRFilter;

    namespace command {
      using ::dynamicgraph::command::Command;
      using ::dynamicgraph::command::Value;
      
      template <class sigT, class coefT>
      class SetElement : public Command
      {
      public:
    	SetElement (FIRFilter < sigT, coefT > & entity,
		    const std::string& docstring);
	Value doExecute ();
      }; // class SetElement

      template <class sigT, class coefT>
      class GetElement : public Command
      {
      public:
    	GetElement (FIRFilter < sigT, coefT > & entity,
		    const std::string& docstring);
	Value doExecute ();
      }; // class SetElement
    } // namespace command
    
    using ::dynamicgraph::command::Setter;
    using ::dynamicgraph::command::Getter;

    template < class sigT, class coefT >
    class FIRFilter
      : public Entity
    {
    public:
      virtual const std::string& getClassName() const
      {
	return Entity::getClassName();
      }
      static std::string getTypeName( void )
      {
	return "Unknown";
      }
      static const std::string CLASS_NAME;
      
      std::string getDocString () const
      {
	return
	  "Finite impulse response filter\n"
	  "\n"
	  "  Provide the following sum in output signal:\n"
	  "             N                   \n"
	  "             __                  \n"
	  "     y (n) = \\   c  s (n-i)      \n"
	  "             /_   i              \n"
	  "             i=0                 \n"
	  "                                 \n"
	  "  where\n"
	  "    -  c_i are coefficients stored in an array\n"
	  "    -  N is the size of the array\n"
	  "    -  s is the input signal.\n";
      }
    public:
      FIRFilter( const std::string& name )
	: Entity(name)
	, SIN(NULL,"sotFIRFilter("+name+")::input(T)::sin")
	, SOUT(boost::bind(&FIRFilter::compute,this,_1,_2),
	       SIN,
	       "sotFIRFilter("+name+")::output(T)::sout")
      {
	signalRegistration( SIN<<SOUT );
	std::string docstring =
	  "  Set element at rank in array of coefficients\n"
	  "\n"
	  "    Input:\n"
	  "      - positive int: rank\n"
	  "      - element\n";
	addCommand ("setElement",
		    new command::SetElement <sigT, coefT>
		    (*this, docstring));
{'fraction_non_alphanumeric': 0.12089029488193424, 'fraction_numerical': 0.0042933001920686924, 'mean_word_length': 2.400691509796389, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2337660', 'n_tokens_mistral': 2959, 'n_tokens_neox': 2809, 'n_words': 837}