我真的在与Haskell atm挣扎.
我花了将近6个小时编写了一个能够满足我想要的功能.不幸的是我对它的外观并不满意.
有人可以给我任何提示如何重写它吗?
get_connected_area :: Eq generic_type => [[generic_type]] -> (Int, Int) -> [(Int,Int)] -> generic_type -> [(Int,Int)]
get_connected_area habitat point area nullValue
| elem point area = area
| not ((fst point) >= 0) = area
| not ((snd point) >= 0) = area
| not ((fst point) < (length habitat)) = area
| not ((snd point) < (length (habitat!!0))) = area
| (((habitat!!(fst point))!!(snd point))) == nullValue = area
| otherwise =
let new_area = point : …Run Code Online (Sandbox Code Playgroud) 我正在探索boost_compute.不幸的是,文档页面和示例比我需要了解的更少.
鉴于以下缩小的代码:
BOOST_COMPUTE_FUNCTION(bool, add, (int* values, int* results, int constant),
{
// Whats the indexing variable?
// In opencl it would be get_global_id(0)
int index = // ?
results[index] = values[index] + values[index + 1] + values[index + 2] + constant;
});
void compute(float* results, compute::context* ctx, compute::command_queue* queue)
{
compute::vector<float> device_values(100, *ctx);
compute::vector<float> device_results(98, *ctx);
compute::copy(
parameters->values.begin(), parameters->values.end(), device_values.begin(), *queue
);
// Actual computation
// HOW TO CALL 'add' for every device_results element?
compute::copy(
device_results.begin(), device_results.end(), results, *queue
); …Run Code Online (Sandbox Code Playgroud)