Skip to content

Commit 352e17c

Browse files
wilzbach9il
authored andcommitted
Add "Open on run.dlang.io" badges
1 parent e05a5cf commit 352e17c

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

README.md

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,66 @@ Dlang core library for math, finance and a home for Dlang multidimensional array
2323

2424
#### Example (3 sec)
2525
```d
26-
import mir.ndslice;
27-
28-
auto matrix = slice!double(3, 4);
29-
matrix[] = 0;
30-
matrix.diagonal[] = 1;
31-
32-
auto row = matrix[2];
33-
row[3] = 6;
34-
assert(matrix[2, 3] == 6); // D & C index order
26+
/+dub.sdl:
27+
dependency "mir-algorithm" version="~>0.7.0"
28+
+/
29+
30+
void main()
31+
{
32+
import mir.ndslice;
33+
34+
auto matrix = slice!double(3, 4);
35+
matrix[] = 0;
36+
matrix.diagonal[] = 1;
37+
38+
auto row = matrix[2];
39+
row[3] = 6;
40+
assert(matrix[2, 3] == 6); // D & C index order
41+
42+
import std.stdio;
43+
matrix.writeln; // [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 6]]
44+
}
3545
```
3646

47+
[![Open on run.dlang.io](https://img.shields.io/badge/run.dlang.io-open-blue.svg)](https://run.dlang.io/is/on6YTM)
48+
3749
#### Example (30 sec)
3850
```d
39-
import mir.ndslice;
40-
import std.stdio: writefln;
41-
42-
enum fmt = "%(%(%.2f %)\n%)\n";
43-
44-
// Magic sqaure.
45-
// `a` is lazy, each element is computed on-demand.
46-
auto a = magic(5).as!float;
47-
writefln(fmt, a);
48-
49-
// 5x5 grid on sqaure [1, 2] x [0, 1] with values x * x + y.
50-
// `b` is lazy, each element is computed on-demand.
51-
auto b = linspace!float([5, 5], [1f, 2f], [0f, 1f]).map!"a * a + b";
52-
writefln(fmt, b);
53-
54-
// allocate a 5 x 5 contiguous matrix
55-
auto c = slice!float(5, 5);
56-
57-
c[] = transposed(a + b / 2); // no memory allocations here
51+
/+dub.sdl:
52+
dependency "mir-algorithm" version="~>0.7.0"
53+
+/
54+
void main()
55+
{
56+
import mir.ndslice;
57+
import std.stdio : writefln;
58+
59+
enum fmt = "%(%(%.2f %)\n%)\n";
60+
61+
// Magic sqaure.
62+
// `a` is lazy, each element is computed on-demand.
63+
auto a = magic(5).as!float;
64+
writefln(fmt, a);
65+
66+
// 5x5 grid on sqaure [1, 2] x [0, 1] with values x * x + y.
67+
// `b` is lazy, each element is computed on-demand.
68+
auto b = linspace!float([5, 5], [1f, 2f], [0f, 1f]).map!"a * a + b";
69+
writefln(fmt, b);
70+
71+
// allocate a 5 x 5 contiguous matrix
72+
auto c = slice!float(5, 5);
73+
74+
c[] = transposed(a + b / 2); // no memory allocations here
5875
// 1. b / 2 - lazy element-wise operation with scalars
5976
// 2. a + (...) - lazy element-wise operation with other slices
60-
// Both slices must be `contiguous` or one-dimensional.
77+
// Both slices must be `contiguous` or one-dimensional.
6178
// 3. transposed(...) - trasposes matrix view. The result is `universal` (numpy-like) matrix.
6279
// 5. c[] = (...) -- performs element-wise assignment.
63-
writefln(fmt, c);
80+
writefln(fmt, c);
81+
}
6482
```
6583

84+
[![Open on run.dlang.io](https://img.shields.io/badge/run.dlang.io-open-blue.svg)](https://run.dlang.io/is/gSlbMb)
85+
6686
### Our sponsors
6787

6888
[<img src="https://raw.githubusercontent.com/libmir/mir-algorithm/master/images/symmetry.png" height="80" />](http://symmetryinvestments.com/) &nbsp; &nbsp; &nbsp; &nbsp;

0 commit comments

Comments
 (0)