From 6b2d8bf80d49a892eca94801bb9948d6d7dbb34a Mon Sep 17 00:00:00 2001 From: sakchal Date: Thu, 9 May 2024 13:50:51 -0400 Subject: [PATCH 1/2] added simple arrayfire array_api example --- examples/array_api/helloworld.py | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/array_api/helloworld.py diff --git a/examples/array_api/helloworld.py b/examples/array_api/helloworld.py new file mode 100644 index 0000000..c34d4eb --- /dev/null +++ b/examples/array_api/helloworld.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + +####################################################### +# Copyright (c) 2024, ArrayFire +# All rights reserved. +# +# This file is distributed under 3-clause BSD license. +# The complete license agreement can be obtained at: +# http://arrayfire.com/licenses/BSD-3-Clause +######################################################## + +import arrayfire.array_api as xp + +try: + print("Create a 5-by-3 matrix of random floats on the GPU\n") + A = xp.asarray([5, 3, 1, 1]) + print(A) + + print("Element-wise arithmetic\n") + B = xp.sin(A) + 1.5 + print(B) + + print("Matrix Multiplication") + C = xp.multiply(A, B) + print(C) + + print("Create a constant array") + r = xp.full((16, 4, 1, 1), 2) + print(r) + + print("Create 2-by-3 matrix from host data\n") + d = [1, 2, 3, 4, 5, 6] + D = xp.reshape(xp.asarray(d, dtype=xp.int32), (2, 3)) + print(D) + + print("Flip Vertically / Horizontally") + print(A) + print(xp.flip(A, axis=0)) + print(xp.flip(A, axis=1)) + + print("Sum, Min, Max along row / columns") + print(A) + print(xp.min(A, axis=0)) + print(xp.max(A, axis=0)) + + print(xp.sum(A, axis=0)) + print(xp.sum(A, axis=1)) + +except Exception as e: + print("Error: " + str(e)) From 9ae746311e3e8fed14a1cbe5cf86c26cb7d3436f Mon Sep 17 00:00:00 2001 From: sakchal Date: Thu, 9 May 2024 14:15:09 -0400 Subject: [PATCH 2/2] changed shell invocation --- examples/array_api/helloworld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/array_api/helloworld.py b/examples/array_api/helloworld.py index c34d4eb..83088d3 100644 --- a/examples/array_api/helloworld.py +++ b/examples/array_api/helloworld.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python ####################################################### # Copyright (c) 2024, ArrayFire