Skip to content

Instantly share code, notes, and snippets.

@michaltakac
Last active March 6, 2021 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaltakac/683fc00144a5d3c2df85761b5536e0f8 to your computer and use it in GitHub Desktop.
Save michaltakac/683fc00144a5d3c2df85761b5536e0f8 to your computer and use it in GitHub Desktop.
Representing 3D grid with ArrayFire
#include <arrayfire.h>
#include <math.h>
#include <stdio.h>
using namespace af;
int main(int argc, char *argv[])
{
int nx = 4;
int ny = 3;
int nz = 2;
array x = tile(range(nx), 1, ny*nz);
array y = tile(range(dim4(1, ny), 1), nx, nz);
array z = tile(range(dim4(1, nz), 1), nx*ny);
array coords = join(1, flat(x),flat(y),flat(z));
print("coords",coords);
// coords
// [24 3 1 1]
// 0 0 0
// 1 0 0
// 2 0 0
// 3 0 0
// 0 1 0
// 1 1 0
// 2 1 0
// ... ... ...
// 0 2 1
// 1 2 1
// 2 2 1
// 3 2 1
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment