The following code triggers an exception. Commenting out the USE_FAIL_CASE define uses logically equivalent code that works just fine.
#include <arrayfire.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace af;
/*
interleave input arrays as
O H
V D
per input element
*/
array interleave(const array &orig, const array &diag, const array &horiz, const array &vert)
{
array out(orig.dims(0) * 2, orig.dims(1) * 2, orig.dims(2));
int rows = out.dims(0), cols = out.dims(1);
#define USE_FAIL_CASE 1 // comment this to remove failure
#if USE_FAIL_CASE
// I don't understand is why the logically equivalent gfor code fails
gfor(seq chan, 3) {
out(seq(0,rows-1,2), seq(0,cols-1,2), chan) = orig(span,span,chan);
out(seq(1,rows-1,2), seq(0,cols-1,2), chan) = vert(span,span,chan);
out(seq(0,rows-1,2), seq(1,cols-1,2), chan) = horiz(span,span,chan);
out(seq(1,rows-1,2), seq(1,cols-1,2), chan) = diag(span,span,chan);
}
#else
out(seq(0,rows-1,2), seq(0,cols-1,2), span) = orig;
out(seq(1,rows-1,2), seq(0,cols-1,2), span) = vert;
out(seq(0,rows-1,2), seq(1,cols-1,2), span) = horiz;
out(seq(1,rows-1,2), seq(1,cols-1,2), span) = diag;
#endif
out.eval();
return out;
}
// fails with "unhandled exception"
// ArrayFire Exception(203): Invalid input size
// In C:\workspace\af_inst_source\src\api\cpp\array.cpp:531
int main(int argc, char *argv[])
{
try {
setDevice(0);
info();
array a = randu(512, 768, 3);
array b = a, c = a, d = a;
array out = interleave(a, b, c, d);
saveImage("foo.png", out);
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}