Last active
March 6, 2021 18:20
-
-
Save michaltakac/683fc00144a5d3c2df85761b5536e0f8 to your computer and use it in GitHub Desktop.
Representing 3D grid with ArrayFire
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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