コード例 #1
0
ファイル: identity.hpp プロジェクト: npk48/hana
 static constexpr auto apply(Id self, P p, F f) {
     auto x = eval_if(p(self.value),
         make_lazy(compose(f, get_value{}))(self),
         make_lazy(get_value{})(self)
     );
     return test::identity(x);
 }
コード例 #2
0
ファイル: lazy.hpp プロジェクト: nkyriazis/lazy_thrust
        template < class other_iterator >
        lazy& operator=(const lazy<other_iterator> &r)
        {
            thrust::copy(r.begin(), r.end(), begin());
            return *this;
        }

        template < class scalar >
        lazy& operator=(const scalar &s)
        {
            thrust::fill(begin(), end(), s);
            return *this;
        }

        template < class other_iterator >
        auto operator[](const lazy<other_iterator> &i) const
            RETURN(make_lazy(thrust::make_permutation_iterator(begin(), i.begin()),
                             thrust::make_permutation_iterator(begin(), i.end())))
    };

    auto make_range(size_t size)
        RETURN(make_lazy(thrust::make_counting_iterator(0),
                         thrust::make_counting_iterator(0) + size))

    template < class iterator >
    auto reverse(const lazy<iterator> &r)
        RETURN(make_lazy(thrust::make_reverse_iterator(r.end()),
            thrust::make_reverse_iterator(r.begin())))

}
コード例 #3
0
ファイル: operators.hpp プロジェクト: nkyriazis/lazy_thrust
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/

#pragma once

#include "transform.hpp"
#include <thrust/iterator/constant_iterator.h> 

namespace lazy_thrust
{
    template < class scalar >
    auto make_scalar(const scalar &s, size_t size)
        RETURN(make_lazy(thrust::make_constant_iterator(s),
                         thrust::make_constant_iterator(s) + size))

#define BINOP(name, op)                                         \
    namespace detail                                            \
    {                                                           \
        struct name                                             \
        {                                                       \
            template < class T, class U >                       \
            __host__ __device__                                 \
            auto operator()(T a, U b) const RETURN(a op b)      \
        };                                                      \
    }

#define BINOP_IMPL(name, op)                                                                                                \
    template < class iter1, class iter2 >                                                                                   \
    auto make_##name(const lazy<iter1> &r1, const lazy<iter2> &r2) RETURN(transform(join(r1, r2), detail::name()))          \