MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / dist_tile1

Function dist_tile1

examples/getting_started/vectorize.cpp:92–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92static array dist_tile1(array a, array b) {
93 // int feat_len = (int)a.dims(0); // Same as (int)b.dims(0);
94 int alen = (int)a.dims(1);
95 int blen = (int)b.dims(1);
96
97 array dist_mat = constant(0, alen, blen);
98
99 // Iterate through columns of b
100 for (int jj = 0; jj < blen; jj++) {
101 // Get the column vector of b
102 // shape of bvec is (feat_len, 1)
103 array bvec = b(span, jj);
104
105 // Tile avec to be same size as a
106 // shape of bvec_tiled is (feat_len, alen)
107 array bvec_tiled = tile(bvec, 1, alen);
108
109 // Get the sum of absolute differences
110 array sad = sum(abs(bvec_tiled - a));
111
112 // sad is row vector, dist_mat needs column vector
113 // transpose sad and fill in dist_mat
114 dist_mat(span, jj) = sad.T();
115 }
116
117 return dist_mat;
118}
119
120static array dist_tile2(array a, array b) {
121 int feat_len = (int)a.dims(0);

Callers 2

bench_tile1Function · 0.85
mainFunction · 0.85

Calls 6

constantFunction · 0.85
TMethod · 0.80
tileFunction · 0.50
sumFunction · 0.50
absFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected