#include std::cout << "some output" << std::endl; std::cerr << "some error" << std::endl; #include throw std::runtime_error("Unknown exception"); int j = 5; j double sqr(double a) { return a * a; } double a = 2.5; double asqr = sqr(a); asqr class Foo { public: virtual ~Foo() {} virtual void print(double value) const { std::cout << "Foo value = " << value << std::endl; } }; Foo bar; bar.print(1.2); class Bar : public Foo { public: virtual ~Bar() {} virtual void print(double value) const { std::cout << "Bar value = " << 2 * value << std::endl; } }; Foo* bar2 = new Bar; bar2->print(1.2); delete bar2; #include template class FooT { public: explicit FooT(const T& t) : m_t(t) {} void print() const { std::cout << typeid(T).name() << " m_t = " << m_t << std::endl; } private: T m_t; }; template <> class FooT { public: explicit FooT(const int& t) : m_t(t) {} void print() const { std::cout << "m_t = " << m_t << std::endl; } private: int m_t; }; FooT foot1(1.2); foot1.print(); FooT foot2(4); foot2.print(); class Foo11 { public: Foo11() { std::cout << "Foo11 default constructor" << std::endl; } Foo11(const Foo11&) { std::cout << "Foo11 copy constructor" << std::endl; } Foo11(Foo11&&) { std::cout << "Foo11 move constructor" << std::endl; } }; Foo11 f1; Foo11 f2(f1); Foo11 f3(std::move(f1)); #include std::vector v = { 1, 2, 3}; auto iter = ++v.begin(); v *iter ?std::vector #include #include #include "xtl/xbase64.hpp" #include "xeus/xjson.hpp" namespace im { struct image { inline image(const std::string& filename) { std::ifstream fin(filename, std::ios::binary); m_buffer << fin.rdbuf(); } std::stringstream m_buffer; }; xeus::xjson mime_bundle_repr(const image& i) { auto bundle = xeus::xjson::object(); bundle["image/png"] = xtl::base64encode(i.m_buffer.str()); return bundle; } } im::image marie("images/marie.png"); marie #include #include #include "xtl/xbase64.hpp" #include "xeus/xjson.hpp" namespace au { struct audio { inline audio(const std::string& filename) { std::ifstream fin(filename, std::ios::binary); m_buffer << fin.rdbuf(); } std::stringstream m_buffer; }; xeus::xjson mime_bundle_repr(const audio& a) { auto bundle = xeus::xjson::object(); bundle["text/html"] = std::string(""; return bundle; } } au::audio drums("audio/audio.wav"); drums #include "xcpp/xdisplay.hpp" xcpp::display(drums); #include #include "xcpp/xdisplay.hpp" namespace ht { struct html { inline html(const std::string& content) { m_content = content; } std::string m_content; }; xeus::xjson mime_bundle_repr(const html& a) { auto bundle = xeus::xjson::object(); bundle["text/html"] = a.m_content; return bundle; } } // A red rectangle ht::html rect(R"(
Original
)"); xcpp::display(rect, "some_display_id"); // Update the rectangle to be blue rect.m_content = R"(
Updated
)"; xcpp::display(rect, "some_display_id", true); #include #include std::vector to_shuffle = {1, 2, 3, 4}; %timeit std::random_shuffle(to_shuffle.begin(), to_shuffle.end()); #include #include "xtensor/xarray.hpp" #include "xtensor/xio.hpp" #include "xtensor/xview.hpp" xt::xarray arr1 {{1.0, 2.0, 3.0}, {2.0, 5.0, 7.0}, {2.0, 5.0, 7.0}}; xt::xarray arr2 {5.0, 6.0, 7.0}; xt::view(arr1, 1) + arr2 #include #include "xtensor/xarray.hpp" #include "xtensor/xio.hpp" xt::xarray arr {1, 2, 3, 4, 5, 6, 7, 8, 9}; arr.reshape({3, 3}); std::cout << arr; #include "xtensor-blas/xlinalg.hpp" xt::xtensor m = {{1.5, 0.5}, {0.7, 1.0}}; std::cout << "Matrix rank: " << std::endl << xt::linalg::matrix_rank(m) << std::endl; std::cout << "Matrix inverse: " << std::endl << xt::linalg::inv(m) << std::endl; std::cout << "Eigen values: " << std::endl << xt::linalg::eigvals(m) << std::endl; xt::xarray arg1 = xt::arange(9); xt::xarray arg2 = xt::arange(18); arg1.reshape({3, 3}); arg2.reshape({2, 3, 3}); std::cout << xt::linalg::dot(arg1, arg2) << std::endl;