我正在 OCaml 中进行实验,看看如何从内存映射文件读取/写入数值数组。
我想我需要使用 Bigarray 但不确定如何将 Bigarray 数组写入内存映射文件,然后读回?
我似乎在任何地方都找不到例子。我检查了Jane St. core的源代码但没有结果。
我想要做的是在向量上创建一个过滤器,以便删除不通过谓词测试的元素; 但我不太确定如何去做.
我根据谓词评估我的inputer向量中的每个元素,例如我的代码中的is_even函数,在device_vector向量中.如果通过测试则确实如此,如果不通过则为假.
现在我被卡住,因为我现在有这个bool向量,我想收集通过这个谓词测试的元素.我将它存储在bool向量中,因为我想保留结果以过滤其他向量.
#include ...
template<typename T>
struct is_even : thrust::unary_function<T, bool>
{
__host__ __device__
bool operator()(const T &x)
{
return (x%2)==0;
}
};
int main(void)
{
std::cout << "Loading test!" << std::endl;
const int N = 1000000;
thrust::device_vector<int> col1(N);
thrust::device_vector<float> col2(N, 1);
thrust::sequence(col1.begin(), col1.end());
thrust::device_vector<bool> filter(N);
thrust::transform(col1.begin(), col1.end(), filter.begin(), is_even<int>());
// filter col1 and col2 based on filter
return 0;
}
Run Code Online (Sandbox Code Playgroud)