binary_function 和多种类型的 Thrust Reduce

Thrust Reduce with binary_function and multiple types

如何使用 binary_functions 多种类型的推力减小?在我的例子中,我有一个结构体 FaceUV,它有一个成员 'distance'。我想计算距离为 != 0 的所有 FaceUV。我该怎么做?

我以为是这个,但是编译不了:

struct FaceHasUVCmp : public thrust::binary_function<FaceUV, uint32_t, uint32_t> {
    __device__
        uint32_t operator()(const FaceUV& o1, const uint32_t& count) const {
        return count + (o1.distance != 0);
    }
};

float get_percent_of_FACES_with_UVs(thrust::device_ptr<FaceUV> face_uvs, unsigned int size){


    uint32_t num_with_UVs = thrust::reduce(thrust::cuda::par, face_uvs, face_uvs + size, 0, FaceHasUVCmp());

    return num_with_UVs / (float)size;

}

这似乎与这个问题类似:

Thrust reduce not working with non equal input/output types

"As talonmies notes, your reduction does not compile because thrust::reduce expects the binary operator's argument types to match its result type"

所以 thrust::Reduce 是不可能的。我还没想好怎么完成我想做的事情

编辑:我可能需要改用 thrust::transform_reduce,但我也不知道如何使用它。