Using af::average to repeatedly calculate the average of an image works fine, and takes less than a second:
try {
for (int i=0; i<1000; i++) {
std::cout << "I: " << i << std::endl;
af::array a = af::randn(1000, 1000);
af_print(af::mean(af::flat(a)));
}
} catch (af::exception &exception) {
std::cout << "Exception: " << exception.what();
}
However, as soon as I switch from mean to median:
try {
for (int i=0; i<1000; i++) {
std::cout << "I: " << i << std::endl;
af::array a = af::randn(1000, 1000);
af_print(af::median(af::flat(a)));
}
} catch (af::exception &exception) {
std::cout << "Exception: " << exception.what();
}
It takes around 4 seconds and then aborts at iteration ~750 / 1000 with the following error:
Exception: ArrayFire Exception(999): Unknown error
In C:\workspace\af_inst_source\src\api\cpp\median.cpp:3
Using it in a real project, I also got a CUDA out of memory error in another function after some time, which suggests to me that there must be a memory leak in af::median.