Skip to content

Commit

Permalink
Improve example notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Jul 10, 2018
1 parent 815d148 commit 8e94185
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ channels:
- conda-forge
dependencies:
- xeus-cling=0.4.5
- xtensor=0.16.4
- xtensor-blas=0.11.1
- notebook
Binary file modified notebooks/images/xeus-cling.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/images/xtensor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions notebooks/xcpp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,117 @@
"source": [
"%timeit std::random_shuffle(to_shuffle.begin(), to_shuffle.end());"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![xtensor](images/xtensor.png)](https://github.com/QuantStack/xtensor/)\n",
"\n",
"- GitHub repository: https://github.com/QuantStack/xtensor/\n",
"- Online documentation: https://xtensor.readthedocs.io/\n",
"- NumPy to xtensor cheat sheet: http://xtensor.readthedocs.io/en/latest/numpy.html\n",
"\n",
"`xtensor` is a C++ library for manipulating N-D arrays with an API very similar to that of numpy."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"\n",
"#include \"xtensor/xarray.hpp\"\n",
"#include \"xtensor/xio.hpp\"\n",
"#include \"xtensor/xview.hpp\"\n",
"\n",
"xt::xarray<double> arr1\n",
" {{1.0, 2.0, 3.0},\n",
" {2.0, 5.0, 7.0},\n",
" {2.0, 5.0, 7.0}};\n",
"\n",
"xt::xarray<double> arr2\n",
" {5.0, 6.0, 7.0};\n",
"\n",
"xt::view(arr1, 1) + arr2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Together with the C++ Jupyter kernel, `xtensor` offers a similar experience as `NumPy` in the Python Jupyter kernel, including broadcasting and universal functions."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"#include \"xtensor/xarray.hpp\"\n",
"#include \"xtensor/xio.hpp\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xt::xarray<int> arr\n",
" {1, 2, 3, 4, 5, 6, 7, 8, 9};\n",
"\n",
"arr.reshape({3, 3});\n",
"\n",
"std::cout << arr;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include \"xtensor-blas/xlinalg.hpp\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xt::xtensor<double, 2> m = {{1.5, 0.5}, {0.7, 1.0}};\n",
"std::cout << \"Matrix rank: \" << std::endl << xt::linalg::matrix_rank(m) << std::endl;\n",
"std::cout << \"Matrix inverse: \" << std::endl << xt::linalg::inv(m) << std::endl;\n",
"std::cout << \"Eigen values: \" << std::endl << xt::linalg::eigvals(m) << std::endl;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xt::xarray<double> arg1 = xt::arange<double>(9);\n",
"xt::xarray<double> arg2 = xt::arange<double>(18);\n",
"\n",
"arg1.reshape({3, 3});\n",
"arg2.reshape({2, 3, 3});\n",
"\n",
"std::cout << xt::linalg::dot(arg1, arg2) << std::endl;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 8e94185

Please sign in to comment.