Skip to content

Commit

Permalink
[doc] add example
Browse files Browse the repository at this point in the history
  • Loading branch information
parcollet committed Feb 13, 2024
1 parent d8b2a36 commit 00e680f
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions doc/C2pyMagicDemo_nda.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "eb187f68-7c62-4561-89a4-d8f0d10c2f32",
"metadata": {},
"outputs": [],
"source": [
"%load_ext clair.c2py_magic"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5cdfac15-114f-423c-8caa-5ed7aa5c4faa",
"metadata": {},
"outputs": [],
"source": [
"import clair.compiler as C\n",
"C.compile_instructions['nda'] = C.ClangInvocation(env_preamble = \"source $HOME/nda_install/share/nda/ndavars.sh\", cpp_preamble = \"#include <nda/nda.hpp>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f1865b8-2ff3-459b-806b-58a21dbb124b",
"metadata": {},
"outputs": [],
"source": [
"%%c2py -C nda\n",
"int f(nda::array<double,1> const & x) { \n",
"return x[0];}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a36f64c-0a85-4d83-880e-1bcd2fe6d75d",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"a = np.array([13,2])\n",
"print(f(a))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 00e680f

Please sign in to comment.