Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Eigen Demo #66

Closed
wants to merge 10 commits into from
134 changes: 81 additions & 53 deletions notebooks/eigen_demo/eigen_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,46 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "610a5fef-82f3-487e-8ec7-53f3c5276505",
"id": "b172dcbe-7a72-4d1a-8e70-5955dec48735",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting package metadata (current_repodata.json): ...working... done\n",
"Solving environment: ...working... done\n",
"\n",
"\n",
"==> WARNING: A newer version of conda exists. <==\n",
" current version: 22.9.0\n",
" latest version: 23.7.4\n",
"\n",
"Please update conda by running\n",
"\n",
" $ conda update -n base -c conda-forge conda\n",
"\n",
"\n",
"\n",
"# All requested packages already installed.\n",
"\n",
"Retrieving notices: ...working... done\n"
]
}
],
"source": [
"!conda install -y -c conda-forge eigen"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "01d6e223-c6bc-4255-bd2f-a2deb68ea06d",
"metadata": {},
"outputs": [],
"source": [
"%%python\n",
"\n",
"import py, os, sys\n",
"from pytest import mark, raises\n",
"\n",
"cppyy.include('/opt/conda/envs/.venv/include/eigen3/Eigen/Dense')"
"#include <clang/Interpreter/CppInterOp.h>\n",
"Cpp::AddIncludePath(\"/opt/conda/envs/.venv/include\");"
]
},
{
Expand All @@ -33,11 +63,13 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "815bd42b-024a-49c7-9557-fa5bfd8b4496",
"metadata": {},
"outputs": [],
"source": [
"#include \"/opt/conda/envs/.venv/include/eigen3/Eigen/Dense\"\n",
"\n",
"typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> MatrixXd;\n",
"\n",
"Eigen::Vector2d a;\n",
Expand All @@ -55,7 +87,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "bca71004-dec4-4571-8a89-c9c9a54aaeee",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -95,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "9b7e7fee-1edd-427c-a738-0cdf941200c1",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -124,15 +156,15 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "3775e315-652d-4dea-8729-e36549524b62",
"metadata": {},
"outputs": [],
"source": [
"%%python\n",
"\n",
"for i in range(len(a)):\n",
" a[i] = i -1\n",
" a[i] = i - 1\n",
"\n",
"for i in range(len(b)):\n",
" b[i] = i + 1\n",
Expand All @@ -143,7 +175,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "ca77d6ff-3428-4977-9072-9f2f2a904973",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -184,7 +216,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "a01b4c6d-88ea-4cb1-a17e-716e1d813b1b",
"metadata": {},
"outputs": [],
Expand All @@ -196,42 +228,44 @@
"res4d = cppyy.gbl.EigenOperations[\"Eigen::Vector4d\"].PerformOperations(c)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "239c40e4-7b92-40be-bd86-336779f88946",
"metadata": {},
"outputs": [],
"source": [
"// fig = plt.figure()\n",
"// ax = fig.add_subplot(111, projection='3d')\n",
"// ax.quiver(X, Y)\n",
"// ax.set_xlim([-1, 0.5])\n",
"// ax.set_ylim([-1, 1.5])\n",
"// ax.set_zlim([-1, 8])\n",
"// plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "876beb2f-113e-4889-bd10-3e460d17181e",
"id": "680cc0d4-3d7b-441c-8f71-3acdf1b9b3e2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1.0, 2.0, 3.0, 4.0)\n",
"(1.0, 1.0, 2.0, 0.5)\n"
"Requirement already satisfied: matplotlib in /opt/conda/envs/.venv/lib/python3.10/site-packages (3.8.0)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (1.1.1)\n",
"Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (0.11.0)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (4.42.1)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (1.4.5)\n",
"Requirement already satisfied: numpy<2,>=1.21 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (1.26.0)\n",
"Requirement already satisfied: packaging>=20.0 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (23.1)\n",
"Requirement already satisfied: pillow>=6.2.0 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (10.0.1)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (3.1.1)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from matplotlib) (2.8.2)\n",
"Requirement already satisfied: six>=1.5 in /opt/conda/envs/.venv/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)\n"
]
}
],
"source": [
"!pip install matplotlib"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "876beb2f-113e-4889-bd10-3e460d17181e",
"metadata": {},
"outputs": [],
"source": [
"%%python\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.mplot3d import Axes3D\n",
"import numpy as np\n",
"\n",
"origin = [0, 0]\n",
Expand All @@ -240,23 +274,25 @@
"np_res3 = np.array(list(res3d)) \n",
"np_res4 = np.array(list(res4d)) \n",
"\n",
"X, Y = np_res2, np_res3\n",
"\n",
"plt.quiver(*origin, *np_res2, color=['r'], scale=5)\n",
"plt.quiver(*origin, *np_res3, color=['b'], scale=5)\n",
"\n",
" \n",
"ax.quiver(X, Y, Z, U, V, W)\n",
"ax.set_xlim([-1, 0.5])\n",
"ax.set_ylim([-1, 1.5])\n",
"ax.set_zlim([-1, 8])\n",
"\n",
"plt.show()\n",
"\n",
" \n"
"plt.savefig(\"test.jpg\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "fc77ec01-bd62-4a87-b2e1-76141623fc5c",
"metadata": {},
"source": [
"<img src=\"./test.jpg\"/>"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"id": "4078ec69-0b4d-4350-8e6b-2d793bc27491",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -286,14 +322,6 @@
"display_eigen(res3d, \"B\")\n",
"display_eigen(res4d, \"C\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "65bb897c-8251-4898-a6ac-725f4dce8c07",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Binary file added notebooks/eigen_demo/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading