xtensor
is a C++ library meant for numerical analysis with multi-dimensional array expressions.
xtensor
provides
xtensor
.The implementation of the containers of xtensor
is inspired by NumPy, the Python array programming library. Adaptors for existing data structures to be plugged into our expression system can easily be written. In fact, xtensor
can be used to process numpy
data structures inplace using Python's buffer protocol.
xtensor
requires a modern C++ compiler supporting C++14. The following C+ compilers are supported:
In [ ]:
#include <iostream>
std::cout << "some output" << std::endl;
In [ ]:
std::cerr << "some error" << std::endl;
In [ ]:
#include <stdexcept>
In [ ]:
throw std::runtime_error("BAAAD");
Omitting the ;
in the last statement of a cell gives an output
In [ ]:
int i = 4
In [ ]:
int j = 5;
In [ ]:
j
In [ ]:
double sqr(double a)
{
return a * a;
}
In [ ]:
double a = 2.5;
double asqr = sqr(a);
asqr
In [ ]:
class Foo
{
public:
virtual ~Foo() {}
virtual void print(double value) const
{
std::cout << "Foo value = " << value << std::endl;
}
};
In [ ]:
Foo bar;
bar.print(1.2);
In [ ]:
class Bar : public Foo
{
public:
virtual ~Bar() {}
virtual void print(double value) const
{
std::cout << "Bar value = " << 2 * value << std::endl;
}
};
In [ ]:
Foo* bar2 = new Bar;
bar2->print(1.2);
delete bar2;
In [ ]:
#include <typeinfo>
template <class T>
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<int>
{
public:
explicit FooT(const int& t) : m_t(t) {}
void print() const
{
std::cout << "m_t = " << m_t << std::endl;
}
private:
int m_t;
};
In [ ]:
FooT<double> foot1(1.2);
foot1.print();
In [ ]:
FooT<int> foot2(4);
foot2.print();
In [ ]:
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; }
};
In [ ]:
Foo11 f1;
Foo11 f2(f1);
Foo11 f3(std::move(f1));
In [ ]:
#include <vector>
std::vector<int> v = { 1, 2, 3};
auto iter = ++v.begin();
v
In [ ]:
*iter
... and also lambda, universal references, decltype
, etc ...
In [ ]:
?std::vector
In [ ]:
#include <string>
#include <fstream>
#include "xtl/xbase64.hpp"
In [ ]:
std::ifstream fin("images/marie.png", std::ios::binary);
std::stringstream buffer;
buffer << fin.rdbuf();
In [ ]:
xeus::xjson mime;
mime["image/png"] = xtl::base64encode(buffer.str());
In [ ]:
xeus::get_interpreter().display_data(
std::move(mime),
xeus::xjson::object(),
xeus::xjson::object());
In [ ]:
std::ifstream fwav("audio/audio.wav", std::ios::binary);
std::stringstream wav_buffer;
wav_buffer << fwav.rdbuf();
xeus::xjson audio_mime;
In [ ]:
audio_mime["text/html"] =
std::string("<audio controls=\"controls\"><source src=\"data:audio/wav;base64,")
+ xtl::base64encode(wav_buffer.str()) +
"\" type=\"audio/wav\" /></audio>";
In [ ]:
xeus::get_interpreter().display_data(
std::move(audio_mime),
xeus::xjson::object(),
xeus::xjson::object());
In [ ]:
In [ ]:
In [ ]: