| 90 | } |
| 91 | |
| 92 | static 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 | |
| 120 | static array dist_tile2(array a, array b) { |
| 121 | int feat_len = (int)a.dims(0); |