[arrayfire] 61/248: Changed unified/basic.cpp to use C++ api
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:53:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.
commit c5f8b3ce5fc5e99264c46b64af12b3848da6edf2
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Fri Sep 18 10:32:53 2015 -0400
Changed unified/basic.cpp to use C++ api
---
examples/unified/basic.cpp | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/examples/unified/basic.cpp b/examples/unified/basic.cpp
index 36787e9..31d1eac 100644
--- a/examples/unified/basic.cpp
+++ b/examples/unified/basic.cpp
@@ -8,9 +8,6 @@
********************************************************/
#include <arrayfire.h>
-#include <af/backend.h>
-#include <cstdio>
-#include <cstdlib>
#include <vector>
#include <algorithm>
@@ -18,7 +15,6 @@ using namespace af;
std::vector<float> input(100);
-
// Generate a random number between 0 and 1
// return a uniform number in [0,1].
double unifRand()
@@ -28,35 +24,47 @@ double unifRand()
void testBackend()
{
- af_info();
-
- dim_t dims[] = {10, 10, 1, 1};
-
- af_array A = 0;
- af_array B = 0;
+ af::info();
- af_create_array(&A, &(input.front()), 4, dims, af_dtype::f32);
- af_print_array_gen("A", A, 4);
+ af::dim4 dims(10, 10, 1, 1);
- af_constant(&B, 0.5, 4, dims, af_dtype::f32);
- af_print_array_gen("B", B, 4);
+ af::array A(dims, &input.front());
+ af_print(A);
- af_release_array(A);
- af_release_array(B);
+ af::array B = af::constant(0.5, dims, f32);
+ af_print(B);
}
int main(int argc, char *argv[])
{
std::generate(input.begin(), input.end(), unifRand);
- if (AF_SUCCESS == af_set_backend(AF_BACKEND_CPU))
+ try {
+ printf("Trying CPU Backend\n");
+ af::setBackend(AF_BACKEND_CPU);
testBackend();
+ } catch (af::exception& e) {
+ printf("Caught exception when trying CPU backend\n");
+ fprintf(stderr, "%s\n", e.what());
+ }
- if (AF_SUCCESS == af_set_backend(AF_BACKEND_CUDA))
+ try {
+ printf("Trying CUDA Backend\n");
+ af::setBackend(AF_BACKEND_CUDA);
testBackend();
+ } catch (af::exception& e) {
+ printf("Caught exception when trying CUDA backend\n");
+ fprintf(stderr, "%s\n", e.what());
+ }
- if (AF_SUCCESS == af_set_backend(AF_BACKEND_OPENCL))
+ try {
+ printf("Trying OpenCL Backend\n");
+ af::setBackend(AF_BACKEND_OPENCL);
testBackend();
+ } catch (af::exception& e) {
+ printf("Caught exception when trying OpenCL backend\n");
+ fprintf(stderr, "%s\n", e.what());
+ }
#ifdef WIN32 // pause in Windows
if (!(argc == 2 && argv[1][0] == '-')) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list