A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://arrayfire.org/docs/getting_started_2vectorize_8cpp-example.htm below:

ArrayFire: getting_started/vectorize.cpp

#include <stdio.h>

for

(

int

ii = 0; ii < (int)a.

dims

(1); ii++) {

for

(

int

jj = 0; jj < (int)b.

dims

(1); jj++) {

for

(

int

kk = 0; kk < (int)a.

dims

(0); kk++) {

dist_mat(ii, jj) += abs(a(kk, ii) - b(kk, jj));

}

}

}

return dist_mat;

}

array

dist_mat = constant(0, (

int

)a.

dims

(1), (

int

)b.

dims

(1));

for

(

int

ii = 0; ii < (int)a.

dims

(1); ii++) {

array

avec = a(span, ii);

for

(

int

jj = 0; jj < (int)b.

dims

(1); jj++) {

array

bvec = b(span, jj);

dist_mat(ii, jj) = sum(abs(avec - bvec));

}

}

return dist_mat;

}

array

avec = a(span, ii);

for

(

int

jj = 0; jj < (int)b.

dims

(1); jj++) {

array

bvec = b(span, jj);

dist_mat(ii, jj) =

sum

(

abs

(avec - bvec));

}

}

return dist_mat;

}

array

bvec = b(span, jj);

for

(

int

ii = 0; ii < (int)a.

dims

(1); ii++) {

array

avec = a(span, ii);

dist_mat(ii, jj) =

sum

(

abs

(avec - bvec));

}

}

return dist_mat;

}

int

alen = (int)a.

dims

(1);

int

blen = (int)b.

dims

(1);

for (int jj = 0; jj < blen; jj++) {

array

bvec = b(span, jj);

dist_mat(span, jj) = sad.

T

();

}

return dist_mat;

}

int

feat_len = (int)a.

dims

(0);

int

alen = (int)a.

dims

(1);

int

blen = (int)b.

dims

(1);

return dist_mat;

}

static void bench_naive() { dist_naive(A, B); }

static void bench_vec() { dist_vec(A, B); }

static void bench_gfor1() { dist_gfor1(A, B); }

static void bench_gfor2() { dist_gfor2(A, B); }

static void bench_tile1() { dist_tile1(A, B); }

static void bench_tile2() { dist_tile2(A, B); }

int main(int, char **) {

try {

array

d1 = dist_naive(A, B);

array

d2 = dist_vec(A, B);

array

d3 = dist_gfor1(A, B);

array

d4 = dist_gfor2(A, B);

array

d5 = dist_tile1(A, B);

array

d6 = dist_tile2(A, B);

printf(

"Max. Error for dist_vec : %f\n"

, max<float>(

abs

(d1 - d2)));

printf(

"Max. Error for dist_gfor1: %f\n"

, max<float>(

abs

(d1 - d3)));

printf(

"Max. Error for dist_gfor2: %f\n"

, max<float>(

abs

(d1 - d4)));

printf(

"Max. Error for dist_tile1: %f\n"

, max<float>(

abs

(d1 - d5)));

printf(

"Max. Error for dist_tile2: %f\n"

, max<float>(

abs

(d1 - d6)));

printf("\n");

printf(

"Time for dist_naive: %2.2fms\n"

, 1000 *

timeit

(bench_naive));

printf(

"Time for dist_vec : %2.2fms\n"

, 1000 *

timeit

(bench_vec));

printf(

"Time for dist_gfor1: %2.2fms\n"

, 1000 *

timeit

(bench_gfor1));

printf(

"Time for dist_gfor2: %2.2fms\n"

, 1000 *

timeit

(bench_gfor2));

printf(

"Time for dist_tile1: %2.2fms\n"

, 1000 *

timeit

(bench_tile1));

printf(

"Time for dist_tile2: %2.2fms\n"

, 1000 *

timeit

(bench_tile2));

fprintf(stderr,

"%s\n"

, ex.

what

());

throw;

}

return 0;

}

A multi dimensional data container.

dim4 dims() const

Get dimensions of the array.

array T() const

Get the transposed the array.

An ArrayFire exception class.

virtual const char * what() const

Returns an error message for the exception in a string format.

seq is used to create sequences for indexing af::array

AFAPI array abs(const array &in)

C++ Interface to calculate the absolute value.

array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)

C++ Interface to generate an array with elements set to a specified value.

AFAPI array moddims(const array &in, const dim4 &dims)

C++ Interface to modify the dimensions of an input array to a specified shape.

AFAPI array tile(const array &in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1)

C++ Interface to generate a tiled array.

AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)

C++ Interface to create an array of random numbers uniformly distributed.

AFAPI array sum(const array &in, const int dim=-1)

C++ Interface to sum array elements over a given dimension.

AFAPI double timeit(void(*fn)())


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4