In [1]:
#Run this once to install
%install_ext https://raw.githubusercontent.com/DlangScience/PydMagic/master/pyd_magic.py


Installed pyd_magic.py. To use it, type:
  %load_ext pyd_magic

In [2]:
%load_ext pyd_magic

In [3]:
%%pyd

@pdef!() string hello() {
    return "Hello World!";
}

@pdef!(Docstring!"takes a single int, returns that int converted to a string")
string intToStr(int b)
{
    import std.conv;
    return b.to!string;
}

@pdef!(PyName!"binary_zebra") int zebra()
{
    return 101010101;
}

long[] whereExactlyIntegral(float[] data)
{
    import std.algorithm, std.array;
    return data.filter!(x => x == cast(long)x).map!(x => cast(long)x).array;
}

@pdef!(PyName!"whereExactlyIntegral")
auto whereExactlyIntegral_numpy(float[] data)
{
    import pyd.extra;
    return data.whereExactlyIntegral().d_to_python_numpy_ndarray();
}

In [4]:
hello()


Out[4]:
'Hello World!'

In [5]:
binary_zebra()


Out[5]:
101010101

In [6]:
intToStr(665543)


Out[6]:
'665543'

In [7]:
whereExactlyIntegral([0.23, 0.53, 1.0, 6.0, 3.51])


Out[7]:
array([1, 6], dtype=int64)

In [8]:
import numpy as np
data = np.random.random_integers(0,1000,10000000).astype(np.float32) / 73
whereExactlyIntegral(data).size


Out[8]:
139543

In [ ]: