|
10 | 10 | | OSX | [](http://ci.arrayfire.org/view/All/job/arrayfire-wrappers/job/python-osx/) |
|
11 | 11 | | Linux on ARM | [](http://ci.arrayfire.org/view/All/job/arrayfire-wrappers/job/python-tegrak1/)|
|
12 | 12 |
|
13 |
| -## Example |
14 |
| - |
15 |
| -```python |
16 |
| -import arrayfire as af |
17 |
| - |
18 |
| -# Display backend information |
19 |
| -af.info() |
20 |
| - |
21 |
| -# Generate a uniform random array with a size of 5 elements |
22 |
| -a = af.randu(5, 1) |
23 |
| - |
24 |
| -# Print a and its minimum value |
25 |
| -af.display(a) |
26 |
| - |
27 |
| -# Print min and max values of a |
28 |
| -print("Minimum, Maximum: ", af.min(a), af.max(a)) |
29 |
| -``` |
30 |
| - |
31 |
| -## Sample outputs |
| 13 | +## Documentation |
32 | 14 |
|
33 |
| -On an AMD GPU: |
| 15 | +Documentation for this project can be found [over here](http://arrayfire.org/arrayfire-python/). |
34 | 16 |
|
35 |
| -``` |
36 |
| -Using opencl backend |
37 |
| -ArrayFire v3.0.1 (OpenCL, 64-bit Linux, build 17db1c9) |
38 |
| -[0] AMD : Spectre |
39 |
| --1- AMD : AMD A10-7850K Radeon R7, 12 Compute Cores 4C+8G |
40 |
| -
|
41 |
| -[5 1 1 1] |
42 |
| -0.4107 |
43 |
| -0.8224 |
44 |
| -0.9518 |
45 |
| -0.1794 |
46 |
| -0.4198 |
47 |
| -
|
48 |
| -Minimum, Maximum: 0.17936542630195618 0.9517996311187744 |
49 |
| -``` |
50 |
| - |
51 |
| -On an NVIDIA GPU: |
| 17 | +## Example |
52 | 18 |
|
| 19 | +```python |
| 20 | +# Monte Carlo estimation of pi |
| 21 | +def calc_pi_device(samples): |
| 22 | + # Simple, array based API |
| 23 | + # Generate uniformly distributed random numers |
| 24 | + x = af.randu(samples) |
| 25 | + y = af.randu(samples) |
| 26 | + # Supports Just In Time Compilation |
| 27 | + # The following line generates a single kernel |
| 28 | + within_unit_circle = (x * x + y * y) < 1 |
| 29 | + # Intuitive function names |
| 30 | + return 4 * af.count(within_unit_circle) / samples |
53 | 31 | ```
|
54 |
| -Using cuda backend |
55 |
| -ArrayFire v3.0.0 (CUDA, 64-bit Linux, build 86426db) |
56 |
| -Platform: CUDA Toolkit 7, Driver: 346.46 |
57 |
| -[0] Tesla K40c, 12288 MB, CUDA Compute 3.5 |
58 |
| --1- GeForce GTX 750, 1024 MB, CUDA Compute 5.0 |
59 |
| -
|
60 |
| -Generate a random matrix a: |
61 |
| -[5 1 1 1] |
62 |
| -0.7402 |
63 |
| -0.9210 |
64 |
| -0.0390 |
65 |
| -0.9690 |
66 |
| -0.9251 |
67 |
| -
|
68 |
| -Minimum, Maximum: 0.039020489901304245 0.9689629077911377 |
69 |
| -``` |
70 |
| - |
71 |
| -Fallback to CPU when CUDA and OpenCL are not availabe: |
72 | 32 |
|
73 |
| -``` |
74 |
| -Using cpu backend |
75 |
| -ArrayFire v3.0.0 (CPU, 64-bit Linux, build 86426db) |
76 |
| -
|
77 |
| -Generate a random matrix a: |
78 |
| -[5 1 1 1] |
79 |
| -0.0000 |
80 |
| -0.1315 |
81 |
| -0.7556 |
82 |
| -0.4587 |
83 |
| -0.5328 |
84 |
| -
|
85 |
| -Minimum, Maximum: 7.825903594493866e-06 0.7556053400039673 |
86 |
| -``` |
87 | 33 |
|
88 | 34 | Choosing a particular backend can be done using `af.backend.set( backend_name )` where backend_name can be one of: "_cuda_", "_opencl_", or "_cpu_". The default device is chosen in the same order of preference.
|
89 | 35 |
|
|
0 commit comments