Last active
March 18, 2020 18:10
-
-
Save vigsterkr/e30a413ef7a91dae5d8fe0235e07af29 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": {}, | |
"outputs": [], | |
"source": [ | |
"#pragma cling add_include_path(\"/home/wiking/shogun/src\")\n", | |
"#pragma cling add_include_path(\"/home/wiking/shogun/build/src\")\n", | |
"#pragma cling add_include_path(\"/home/wiking/shogun/third_party/spdlog/include\")\n", | |
"#pragma cling add_library_path(\"/home/wiking/shogun/build/bin\")\n", | |
"#pragma cling add_library_path(\"/home/wiking/ngraph-prefix/lib\")\n", | |
"#pragma cling load(\"libshogun-core\")\n", | |
"#pragma cling load(\"libshogun-engine\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"#include <shogun/mathematics/graph/Graph.h>\n", | |
"#include <shogun/mathematics/graph/nodes/Input.h>\n", | |
"#include <shogun/mathematics/graph/nodes/MatMul.h>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"using namespace shogun;\n", | |
"\n", | |
"SGVector<float64_t> X1{1, 2, 3};\n", | |
"SGVector<float64_t> X2{4, 5, 6};" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"using namespace shogun::graph;\n", | |
"using namespace std;\n", | |
"\n", | |
"auto A = make_shared<node::Input>(Shape{3}, element_type::FLOAT64);\n", | |
"auto B = make_shared<node::Input>(Shape{3}, element_type::FLOAT64);\n", | |
"\n", | |
"auto output = make_shared<node::MatMul>(A, B);\n", | |
"\n", | |
"auto gr = make_shared<Graph>(\n", | |
" vector{A, B}, vector<shared_ptr<node::Node>>{output});" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"gr->build(GRAPH_BACKEND::SHOGUN);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"using namespace shogun;\n", | |
"using namespace shogun::graph;\n", | |
"using namespace std;\n", | |
"\n", | |
"auto result = gr->evaluate(\n", | |
" vector{make_shared<Tensor>(X1), make_shared<Tensor>(X2)});\n", | |
"\n", | |
"auto result1 = result[0]->as<SGVector<float64_t>>();" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{ 32.000000 }" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"result1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"gr->build(GRAPH_BACKEND::NGRAPH);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"using namespace shogun;\n", | |
"using namespace shogun::graph;\n", | |
"using namespace std;\n", | |
"\n", | |
"auto r = gr->evaluate(\n", | |
" vector{make_shared<Tensor>(X1), make_shared<Tensor>(X2)});" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{ 32.000000 }" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"r[0]->as<SGVector<float64_t>>()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "C++17", | |
"language": "C++17", | |
"name": "xcpp17" | |
}, | |
"language_info": { | |
"codemirror_mode": "text/x-c++src", | |
"file_extension": ".cpp", | |
"mimetype": "text/x-c++src", | |
"name": "c++", | |
"version": "17" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment