all_of binary predicate

29 views
Skip to first unread message

Dirk Vanden Boer

unread,
May 31, 2017, 11:43:51 AM5/31/17
to boost-compute
Hi,

Im trying to compare two float vectors using a custom compare that takes nan values into account.

I'm currently trying something like this:

BOOST_COMPUTE_FUNCTION(bool, float_equal, (value_type x, value_type y),
{
    if (isnan(x) && isnan(y))
    {
        return true;
    }

    if (isnan(x) || isnan(y))
    {
        return false;
    }
       
       return x == y;

});


return boost::compute::all_of(
    boost::compute::make_zip_iterator(boost::make_tuple(begin1, begin2)),
    boost::compute::make_zip_iterator(boost::make_tuple(end1, end2)),
    float_equal
);

Except the all_of function only accepts unary operators.

Wouldn't it make sense for the all_of algorithm to support a binary predicate so it can be used in combination with a zip_iterator.
Or am I overlooking something that would make this possible?

My current solution is to perform a transform_reduce that counts the number of non_equals but the all_of solution seems more natural.

Kind regards,
Dirk

Jakub Szuppe

unread,
May 31, 2017, 12:33:20 PM5/31/17
to Dirk Vanden Boer, boost-compute

--
You received this message because you are subscribed to the Google Groups "boost-compute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boost-compute+unsubscribe@googlegroups.com.
To post to this group, send email to boost-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/boost-compute/a0e5e04f-1647-4621-8757-ea774c27b05d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dirk Vanden Boer

unread,
Jun 1, 2017, 3:37:27 AM6/1/17
to boost-compute, dirk...@gmail.com
Thanks a lot! That did the trick.
To unsubscribe from this group and stop receiving emails from it, send an email to boost-comput...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages