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
//==============================================================================
/*!
 * \file
**/
#ifndef BOOST_SIMD_IEEE_FUNCTIONS_EPS_HPP_INCLUDED
#define BOOST_SIMD_IEEE_FUNCTIONS_EPS_HPP_INCLUDED
#include <boost/simd/include/functor.hpp>
#include <boost/dispatch/include/functor.hpp>

/*!
 * \ingroup boost_simd_ieee
 * \defgroup boost_simd_ieee_eps eps
 *
 * \par Description
 * Returns 2 times the Machine epsilon
 * \par
 * The Machine epsilon gives an upper bound on the relative
 * error due to rounding in floating point arithmetic. Typically $2^{-53}$
 * for floating point doubles and $2^{-24}$ for
 * floats. MATLAB(TM) language defines the value eps
 * as the distance from 1.0 to the next larger double
 * which is two times the machine epsilon...
 * Returns one for integer types.
 *
 * \par Header file
 *
 * \code
 * #include <nt2/include/functions/eps.hpp>
 * \endcode
 *
 *
 * \synopsis
 *
 * \code
 * namespace boost::simd
 * {
 *   template <class A0>
 *     meta::call<tag::eps_(A0)>::type
 *     eps(const A0 & a0);
 * }
 * \endcode
 *
 * \param a0 the unique parameter of eps
 *
 * \return a value of the same type as the parameter
 *
 * \par Notes
 * In SIMD mode, this function acts elementwise on the inputs vectors elements
 * \par
 *
**/

namespace boost { namespace simd { namespace tag
  {
    /*!
     * \brief Define the tag eps_ of functor eps
     *        in namespace boost::simd::tag for toolbox boost.simd.ieee
    **/
    struct eps_ : ext::elementwise_<eps_> { typedef ext::elementwise_<eps_> parent; };
  }
  BOOST_DISPATCH_FUNCTION_IMPLEMENTATION(tag::eps_, eps, 1)
} }

#endif

// modified by jt the 25/12/2010


text:
/*
 * Type and constant definitions
 * Copyright (C) 2019  Robin Scheibler
 *
 * 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.
 *
 * You should have received a copy of the MIT License along with this program. If
 * not, see <https://opensource.org/licenses/MIT>.
 */

/* This file contains type and constants definitions */
#ifndef __COMMON_HPP__
#define __COMMON_HPP__

#include <iostream>
#include <Eigen/Dense>

extern float libroom_eps;  // epsilon is the precision for floating point computations. It is defined in libroom.cpp

template<size_t D>
using Vectorf = Eigen::Matrix<float, D, 1>;

using MatrixXf = Eigen::MatrixXf;
typedef Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic> MatrixXb;
typedef Eigen::Matrix<bool, Eigen::Dynamic, 1> VectorXb;

/* The 'entry' type is simply defined as an array of 2 floats.
 * It represents an entry that is logged by the microphone
 * during the ray_tracing execution.
 * The first one of those float will be the travel time of a ray reaching
 * the microphone. The second one will be the energy of this ray.*/

struct Hit
{
  float distance = 0.f;
  Eigen::ArrayXf transmitted;  // vector of transmitted energy over frequency bands

  Hit(int _nfreq)
  {
    transmitted.resize(_nfreq);
    transmitted.setOnes();
  };
  Hit(const float _d, const Eigen::ArrayXf &_t)
    : distance(_d), transmitted(_t) {}
};

typedef std::vector<std::list<Hit>> HitLog;

size_t get_new_size(size_t val, size_t cur_size)
{
  size_t new_size = cur_size;
  while (val >= new_size)
    new_size *= 2;
  return new_size;
}

class Histogram2D
{
  size_t rows, cols;
  Eigen::ArrayXXf array;
  Eigen::ArrayXXi counts;

  public:
    Histogram2D() {}  // empty constructor
    Histogram2D(int _r, int _c) : rows(_r), cols(_c)
    {
      init(rows, cols);
    }

    void init(int rows, int cols)
    {
      array.resize(rows, cols);
      array.setZero();
      counts.resize(rows, cols);
      counts.setZero();
    }

    void reset()
    {
      array.setZero();
      counts.setZero();
    }

    void resize_rows(int new_rows)
    {
      auto old_rows = array.rows();
      // this will resize the array while preserving the content
      array.conservativeResize(new_rows, Eigen::NoChange);
      counts.conservativeResize(new_rows, Eigen::NoChange);
      // We need to initialize the new elements
      if (new_rows > old_rows)
      {
        array.bottomRows(new_rows - old_rows).setZero();
        counts.bottomRows(new_rows - old_rows).setZero();
      }
    }

    void resize_cols(int new_cols)
    {
      auto old_cols = array.cols();
      // this will resize the array while preserving the content
      array.conservativeResize(Eigen::NoChange, new_cols);
      counts.conservativeResize(Eigen::NoChange, new_cols);
      // We need to initialize the new elements
      if (new_cols > old_cols)
      {
        array.rightCols(new_cols - old_cols).setZero();
        counts.rightCols(new_cols - old_cols).setZero();
      }
    }

    void log(Eigen::Index row, Eigen::Index col, float val)
    {
      if (row >= array.rows())
        resize_rows(get_new_size(row, array.rows()));

      if (col >= array.cols())
        resize_cols(get_new_size(col, array.cols()));

      array.coeffRef(row, col) += val;
      counts.coeffRef(row, col)++;
    }

    void log_col(Eigen::Index col, const Eigen::ArrayXf &val)
    {
      if (col >= array.cols())
        resize_cols(get_new_size(col, array.cols()));

      array.col(col) += val;
      counts.col(col) += 1;
    }

    void log_row(Eigen::Index row, const Eigen::ArrayXf &val)
    {
      if (row >= array.rows())
        resize_rows(get_new_size(row, array.rows()));

      array.row(row) += val;
      counts.row(row) += 1;
    }

    float bin(Eigen::Index row, Eigen::Index col) const
    {
      if (counts.coeff(row, col) != 0)
        return array.coeff(row, col) / counts.coeff(row, col);
      else
        return 0.f;
    }

    Eigen::ArrayXXf get_hist() const
    {
      return array;
    }
};

#endif // __COMMON_HPP__

ext: hpp

max_stars_repo_name: HemaZ/pyroomacoustics

max_issues_repo_name: HemaZ/pyroomacoustics

max_forks_repo_name: HemaZ/pyroomacoustics