Created
September 6, 2016 13:39
-
-
Save lukasbindreiter/249abd48b2e77665a41282fb2ffed5d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import arrayfire as af\n", | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# create numpy array of different types\n", | |
"nparr = np.ascontiguousarray([12.45645, 3.235, 76.123834, 54.2, 56, 81.99])\n", | |
"np_double = nparr.astype(np.float64)\n", | |
"np_float = nparr.astype(np.float32)\n", | |
"np_uint_8 = nparr.astype(np.uint8)\n", | |
"np_int_32 = nparr.astype(np.int32)\n", | |
"np_uint_32 = nparr.astype(np.uint32)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[ 12.45645 3.235 76.123834 54.2 56. 81.99 ]\n", | |
"[ 12.45645046 3.2349999 76.1238327 54.20000076 56. 81.98999786]\n", | |
"[12 3 76 54 56 81]\n", | |
"[12 3 76 54 56 81]\n", | |
"[12 3 76 54 56 81]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(np_double)\n", | |
"print(np_float)\n", | |
"print(np_uint_8)\n", | |
"print(np_int_32)\n", | |
"print(np_uint_32)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# convert numpy to arrayfire\n", | |
"af_double = af.interop.np_to_af_array(np_double)\n", | |
"af_float = af.interop.np_to_af_array(np_float)\n", | |
"af_uint_8 = af.interop.np_to_af_array(np_uint_8)\n", | |
"af_int_32 = af.interop.np_to_af_array(np_int_32)\n", | |
"af_uint_32 = af.interop.np_to_af_array(np_uint_32)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"arrayfire.Array()\n", | |
"Type: double\n", | |
"[6 1 1 1]\n", | |
" 12.4565 \n", | |
" 3.2350 \n", | |
" 76.1238 \n", | |
" 54.2000 \n", | |
" 56.0000 \n", | |
" 81.9900 \n", | |
"\n", | |
"\n", | |
"arrayfire.Array()\n", | |
"Type: float\n", | |
"[6 1 1 1]\n", | |
" 12.4565 \n", | |
" 3.2350 \n", | |
" 76.1238 \n", | |
" 54.2000 \n", | |
" 56.0000 \n", | |
" 81.9900 \n", | |
"\n", | |
"\n", | |
"arrayfire.Array()\n", | |
"Type: unsigned char\n", | |
"[6 1 1 1]\n", | |
" 12 \n", | |
" 3 \n", | |
" 76 \n", | |
" 54 \n", | |
" 56 \n", | |
" 81 \n", | |
"\n", | |
"\n", | |
"arrayfire.Array()\n", | |
"Type: long int\n", | |
"[6 1 1 1]\n", | |
"12884901900 \n", | |
"231928234060 \n", | |
"347892351032 \n", | |
"-7780735813443758960 \n", | |
"8589934592 \n", | |
" 3 \n", | |
"\n", | |
"\n", | |
"arrayfire.Array()\n", | |
"Type: unsigned long int\n", | |
"[6 1 1 1]\n", | |
"12884901900 \n", | |
"231928234060 \n", | |
"347892351032 \n", | |
"10666011558800282774 \n", | |
"4294967298 \n", | |
" 2 \n", | |
"\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"print(af_double)\n", | |
"print(af_float)\n", | |
"print(af_uint_8)\n", | |
"print(af_int_32)\n", | |
"print(af_uint_32)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# example operation\n", | |
"af_double += 3\n", | |
"af_float += 3\n", | |
"af_uint_8 += 3\n", | |
"af_int_32 += 3\n", | |
"af_uint_32 += 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[ 15.45645 6.235 79.123834 57.2 59. 84.99 ]\n", | |
"[ 15.45645046 6.23499966 79.1238327 57.20000076 59. 84.98999786]\n", | |
"[15 0 6 0 79 0]\n", | |
"[15 3 79 54 59 81]\n", | |
"[15 3 79 54 59 81]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(af_double.__array__())\n", | |
"print(af_float.__array__())\n", | |
"print(af_uint_8.__array__())\n", | |
"print(af_int_32.__array__())\n", | |
"print(af_uint_32.__array__())" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [Root]", | |
"language": "python", | |
"name": "Python [Root]" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment