Exemple #1
0
    result_type operator()(A0& yi, A1& inputs) const
    {
        yi.resize(inputs.extent());
        const child0 & x   =  boost::proto::child_c<0>(inputs);
        if (numel(x) <=  1)
            BOOST_ASSERT_MSG(numel(x) >  1, "Interpolation requires at least two sample points in each dimension.");
        else
        {
            BOOST_ASSERT_MSG(issorted(x, 'a'), "for 'nearest' interpolation x values must be sorted in ascending order");
            const child1 & y   =  boost::proto::child_c<1>(inputs);
            BOOST_ASSERT_MSG(numel(x) == numel(y), "The grid vectors do not define a grid of points that match the given values.");
            const child2 & xi  =  boost::proto::child_c<2>(inputs);
            bool extrap = false;
            value_type extrapval = Nan<value_type>();
            choices(inputs, extrap, extrapval, N1());
            table<index_type>   index = bsearch (x, xi);
            table<value_type>  dx    =  xi-x(index);
            table<index_type> indexp1 =  oneplus(index);
            yi = y(nt2::if_else(lt(nt2::abs(xi-x(index)), nt2::abs(xi-x(indexp1))), index,  indexp1));
            value_type  b =  value_type(x(begin_));
            value_type  e =  value_type(x(end_));
            if (!extrap) yi = nt2::if_else(nt2::logical_or(boost::simd::is_nge(xi, b),
                                               boost::simd::is_nle(xi, e)), extrapval, yi);
        }

        return yi;
    }
Exemple #2
0
    BOOST_FORCEINLINE result_type
    operator()(A0& a0, A1& a1) const
    {
      a0.resize(a1.extent());

      input_type input = boost::proto::child_c<0>(a1);
      extent_type ext = input.extent();
      std::size_t dim = nt2::ndims(ext);
      std::size_t red = reduction_dim(a1, boost::mpl::bool_<!(boost::proto::arity_of<A1>::value <= 1)>());

#if 0
      if((red - 1 < ext.size() && ext[red-1] == 1) || ext.size() < red)
        return nt2::run_assign(a0, input);
#endif

      if(dim == 1 && red == 1)
      {
        nt2::run( a0, 0u
                , nt2::fold( input
                           , typename nt2::make_functor<Neutral1, A0>::type()
                           , typename nt2::make_functor<O1, A0>::type()
                           , typename nt2::make_functor<T1, A0>::type()
                           )
                );

      }
      else if(red == 1)
      {
        nt2::inner_fold( a0
                       , input
                       , typename nt2::make_functor<Neutral1, A0>::type()
                       , typename nt2::make_functor<O1, A0>::type()
                       , typename nt2::make_functor<T1, A0>::type()
                       );
      }
#if 0
      else if(red == ext.size())
      {
        nt2::outer_fold( a0
                       , input
                       , typename nt2::make_functor<Neutral1, A0>::type()
                       , typename nt2::make_functor<O1, A0>::type()
                       , typename nt2::make_functor<T1, A0>::type()
                       );
      }
#endif
      else
      {
        std::size_t inner = red-1 < ext.size() ? ext[red-1] : 1;

        std::size_t lo = std::accumulate( ext.begin()
                                        , ext.begin()+std::min(red-1, dim)
                                        , std::size_t(1)
                                        , std::multiplies<std::size_t>()
                                        );

        std::size_t hi = std::accumulate( ext.begin()+std::min(red, dim)
                                        , ext.begin()+dim
                                        , std::size_t(1)
                                        , std::multiplies<std::size_t>()
                                        );

        nt2::partial_fold( reshape(a0, of_size(lo, hi))
                         , reshape(input, of_size(lo, inner, hi))
                         , typename nt2::make_functor<Neutral1, A0>::type()
                         , typename nt2::make_functor<O1, A0>::type()
                         , typename nt2::make_functor<T1, A0>::type()
                         );
      }

      return a0;
    }