Skip to content

Commit

Permalink
Docs adapted to Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
JdeH committed Dec 30, 2017
1 parent 828fee6 commit abd2c05
Show file tree
Hide file tree
Showing 28 changed files with 10,597 additions and 49 deletions.
2 changes: 1 addition & 1 deletion numscrypt/__base__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ns_version = '0.0.36'
ns_version = '0.0.37'
5,341 changes: 5,341 additions & 0 deletions numscrypt/development/automated_tests/ndarray/__javascript__/autotest.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(function () {
var basics = {};
var module_fft = {};
var module_linalg = {};
var org = {};
var __name__ = '__main__';
__nest__ (org, 'transcrypt.autotester', __init__ (__world__.org.transcrypt.autotester));
__nest__ (basics, '', __init__ (__world__.basics));
__nest__ (module_linalg, '', __init__ (__world__.module_linalg));
__nest__ (module_fft, '', __init__ (__world__.module_fft));
var autoTester = org.transcrypt.autotester.AutoTester ();
autoTester.run (basics, 'basics');
autoTester.run (module_linalg, 'module_linalg');
autoTester.run (module_fft, 'module_fft');
autoTester.done ();
__pragma__ ('<use>' +
'basics' +
'module_fft' +
'module_linalg' +
'org.transcrypt.autotester' +
'</use>')
__pragma__ ('<all>')
__all__.__name__ = __name__;
__all__.autoTester = autoTester;
__pragma__ ('</all>')
}) ();
62 changes: 62 additions & 0 deletions numscrypt/development/automated_tests/ndarray/autotest.html

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions numscrypt/development/automated_tests/ndarray/autotest.min.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
__nest__ (
__all__,
'basics', {
__all__: {
__inited__: false,
__init__: function (__all__) {
var __name__ = 'basics';
if (__envir__.executor_name == __envir__.transpiler_name) {
var num = __init__ (__world__.numscrypt);
}
var run = function (autoTester) {
var z = num.zeros (tuple ([4, 3]), 'int32');
autoTester.check ('Zeros', z.tolist (), '<br>');
var o = num.ones (tuple ([4, 5]));
autoTester.check ('Ones', o.astype ('int32').tolist ());
var i = num.identity (3, 'int32');
autoTester.check ('Identity', i.tolist (), '<br>');
var a = num.array (list ([list ([1, 1, 2, 3]), list ([4, 5, 6, 7]), list ([8, 9, 10, 12])]));
autoTester.check ('Matrix a', a.tolist (), '<br>');
autoTester.check ('Transpose of a', a.transpose ().tolist (), '<br>');
var b = num.array (list ([list ([2, 2, 4, 6]), list ([8, 10, 12, 14]), list ([16, 18, 20, 24])]));
var bp = b.transpose ();
autoTester.check ('Matrix b', b.tolist (), '<br>');
autoTester.check ('Permutation of b', bp.tolist (), '<br>');
var c = num.array (list ([list ([1, 2, 3, 4]), list ([5, 6, 7, 8]), list ([9, 10, 11, 12])]), 'int32');
autoTester.check ('Shape c', tuple (c.shape), '<br>');
autoTester.check ('Matrix c', c.tolist (), '<br>');
var ct = c.transpose ();
autoTester.check ('Shape ct', tuple (ct.shape), '<br>');
autoTester.check ('Transpose of c', ct.tolist (), '<br>');
var __left0__ = num.hsplit (c, 2);
var cs0 = __left0__ [0];
var cs1 = __left0__ [1];
autoTester.check ('Matrix cs0', cs0.tolist (), '<br>');
autoTester.check ('Matrix cs1', cs1.tolist (), '<br>');
var ci = num.hstack (tuple ([cs1, cs0]));
autoTester.check ('Matrix ci', ci.tolist (), '<br>');
var __left0__ = num.hsplit (ct, 3);
var cts0 = __left0__ [0];
var cts1 = __left0__ [1];
var cts2 = __left0__ [2];
autoTester.check ('Matrix cts0', cts0.tolist (), '<br>');
autoTester.check ('Matrix cts1', cts1.tolist (), '<br>');
autoTester.check ('Matrix cts2', cts2.tolist (), '<br>');
var cti = num.hstack (tuple ([cts2, cts1, cts0]));
autoTester.check ('Matrix ci', cti.tolist (), '<br>');
var d = num.array (list ([list ([13, 14]), list ([15, 16]), list ([17, 18]), list ([19, 20])]), 'int32');
autoTester.check ('Matrix d', d.tolist (), '<br>');
var dt = d.transpose ();
autoTester.check ('Permutation of d', dt.tolist (), '<br>');
var __left0__ = num.vsplit (d, 4);
var ds0 = __left0__ [0];
var ds1 = __left0__ [1];
var ds2 = __left0__ [2];
var ds3 = __left0__ [3];
autoTester.check ('Matrix ds0', ds0.tolist (), '<br>');
autoTester.check ('Matrix ds1', ds1.tolist (), '<br>');
autoTester.check ('Matrix ds2', ds2.tolist (), '<br>');
autoTester.check ('Matrix ds3', ds3.tolist (), '<br>');
var di = num.vstack (tuple ([ds3, ds2, ds1, ds0]));
autoTester.check ('Matrix di', di.tolist (), '<br>');
var __left0__ = num.vsplit (dt, 2);
var dts0 = __left0__ [0];
var dts1 = __left0__ [1];
autoTester.check ('Matrix dts0', dts0.tolist (), '<br>');
autoTester.check ('Matrix dts1', dts1.tolist (), '<br>');
var dti = num.vstack (tuple ([dts1, dts0]));
autoTester.check ('Matrix dti', dti.tolist (), '<br>');
var v0 = num.array (range (10));
var v1 = num.array (tuple ([1, 2, 3, 1, 2, 3, 1, 2, 3, 1]));
a.__setitem__ ([1, 0], 177);
var el = b.__getitem__ ([1, 2]);
var bsl0 = b.__getitem__ ([1, tuple ([1, 3, 1])]);
var bsl1 = b.__getitem__ ([tuple ([1, 2, 1]), tuple ([1, 3, 1])]);
var bsl2 = b.__getitem__ ([tuple ([1, 2, 1]), 1]);
var bsl3 = b.__getitem__ ([1, tuple ([1, 3, 1])]);
var bsl4 = b.__getitem__ ([tuple ([0, null, 1]), 1]);
var bsl5 = b.__getitem__ ([1, tuple ([1, 3, 1])]);
var bsl6 = b.__getitem__ ([1, tuple ([1, 3, 1])]);
var bsl7 = b.__getitem__ ([1, tuple ([2, 3, 1])]);
var bpsl0 = bp.__getitem__ ([1, tuple ([1, 3, 1])]);
var bpsl1 = bp.__getitem__ ([tuple ([1, 2, 1]), tuple ([1, 3, 1])]);
var bpsl2 = bp.__getitem__ ([1, tuple ([0, null, 1])]);
var bpsl3 = bp.__getitem__ ([1, tuple ([1, 3, 1])]);
var bpsl4 = bp.__getitem__ ([tuple ([0, null, 1]), 1]);
var bpsl5 = bp.__getitem__ ([3, tuple ([1, 3, 1])]);
var bpsl6 = bp.__getitem__ ([tuple ([2, 4, 1]), tuple ([1, 3, 1])]);
var bpsl7 = bp.__getitem__ ([tuple ([2, 4, 1]), tuple ([2, 3, 1])]);
var sum = __add__ (a, b);
var dif = __sub__ (a, b);
var prod = __mul__ (a, b);
var quot = __truediv__ (a, b);
var dot = __matmul__ (c, d);
var vsum = __add__ (v0, v1);
var vel = __getitem__ (vsum, 6);
__setitem__ (vsum, 6, 70);
var mul_a3 = __mul__ (a, 3);
var mul_3a = __mul__ (3, a);
var div_a3 = __truediv__ (a, 3.1234567);
var div_3a = __truediv__ (3.1234567, a);
var add_a3 = __add__ (a, 3);
var add_3a = __add__ (3, a);
var sub_a3 = __sub__ (a, 3);
var sub_3a = __sub__ (3, a);
var neg_a = __neg__ (a);
autoTester.check ('El a [1, 2, 3] alt', a.tolist (), '<br>');
autoTester.check ('El b [1, 2, 3]', el, '<br>');
autoTester.check ('Sl b0', bsl0.tolist (), '<br>');
autoTester.check ('Sl b1', bsl1.tolist (), '<br>');
autoTester.check ('Sl b2', bsl2.tolist (), '<br>');
autoTester.check ('Sl b3', bsl3.tolist (), '<br>');
autoTester.check ('Sl b4', bsl4.tolist (), '<br>');
autoTester.check ('Sl b5', bsl5.tolist (), '<br>');
autoTester.check ('Sl b6', bsl6.tolist (), '<br>');
autoTester.check ('Sl b7', bsl7.tolist (), '<br>');
autoTester.check ('Sl bp0', bpsl0.tolist (), '<br>');
autoTester.check ('Sl bp1', bpsl1.tolist (), '<br>');
autoTester.check ('Sl bp2', bpsl2.tolist (), '<br>');
autoTester.check ('Sl bp3', bpsl3.tolist (), '<br>');
autoTester.check ('Sl bp4', bpsl4.tolist (), '<br>');
autoTester.check ('Sl bp5', bpsl5.tolist (), '<br>');
autoTester.check ('Sl bp6', bpsl6.tolist (), '<br>');
autoTester.check ('Sl bp7', bpsl7.tolist (), '<br>');
autoTester.check ('Matrix sum', sum.tolist (), '<br>');
autoTester.check ('Matrix difference', dif.tolist (), '<br>');
autoTester.check ('Matrix product', prod.tolist (), '<br>');
autoTester.check ('Matrix quotient', quot.tolist (), '<br>');
autoTester.check ('Matrix dotproduct', dot.tolist (), '<br>');
autoTester.check ('Vector', v0.tolist (), '<br>');
autoTester.check ('Vector', v1.tolist (), '<br>');
autoTester.check ('El sum old', vel, '<br>');
autoTester.check ('Vector sum new', vsum.tolist (), '<br>');
autoTester.check ('mul_a3', mul_a3.tolist (), '<br>');
autoTester.check ('mul_3a', mul_3a.tolist (), '<br>');
autoTester.check ('div_a3', num.round (div_a3, 2).tolist (), '<br>');
autoTester.check ('div_3a', num.round (div_3a, 2).tolist (), '<br>');
autoTester.check ('add_a3', add_a3.tolist (), '<br>');
autoTester.check ('add_3a', add_3a.tolist (), '<br>');
autoTester.check ('sub_a3', sub_a3.tolist (), '<br>');
autoTester.check ('sub_3a', sub_3a.tolist (), '<br>');
autoTester.check ('neg_a', neg_a.tolist (), '<br>');
var comp_a = __call__ (num.array, num, list ([list ([__add__ (1, complex (0, 2.0)), __sub__ (2, complex (0, 1.0)), 3]), list ([4, __add__ (5, complex (0, 3.0)), 7])]), 'complex128');
var comp_b = __call__ (num.array, num, list ([list ([6, __sub__ (8, complex (0, 1.0))]), list ([__add__ (9, complex (0, 3.0)), 10]), list ([11, __sub__ (12, complex (0, 6.0))])]), 'complex128');
var comp_c = __matmul__ (comp_a, comp_b);
autoTester.check ('comp_a', comp_a.tolist (), '<br>');
autoTester.check ('comp_b', comp_b.tolist (), '<br>');
autoTester.check ('comp_c', comp_c.tolist (), '<br>');
var comp_a_square = comp_a.__getitem__ ([tuple ([0, null, 1]), tuple ([0, 2, 1])]);
var comp_b_square = comp_b.__getitem__ ([tuple ([1, null, 1]), tuple ([0, null, 1])]);
var comp_c_square = __mul__ (comp_a_square, comp_b_square);
var comp_d_square = __truediv__ (comp_a_square, comp_b_square);
var comp_e_square = __add__ (comp_a_square, comp_b_square);
var comp_f_square = __sub__ (comp_a_square, comp_b_square);
autoTester.check ('comp_a_square', comp_a_square.tolist (), '<br>');
autoTester.check ('comp_b_square', comp_b_square.tolist (), '<br>');
autoTester.check ('comp_c_square', comp_c_square.tolist (), '<br>');
autoTester.check ('comp_d_square', num.round (comp_d_square, 2).tolist (), '<br>');
autoTester.check ('comp_e_square', comp_e_square.tolist (), '<br>');
autoTester.check ('comp_f_square', comp_f_square.tolist (), '<br>');
var sliceable_a = __call__ (num.array, num, list ([list ([1, 2, 3, 4]), list ([5, 6, 7, 8]), list ([9, 10, 11, 12]), list ([13, 14, 15, 16])]));
__call__ (autoTester.check, autoTester, 'sliceable_a', __call__ (sliceable_a.tolist, sliceable_a));
var slice_a = sliceable_a.__getitem__ ([tuple ([1, null, 1]), tuple ([1, null, 1])]);
__call__ (autoTester.check, autoTester, 'slice_a');
var sliceable_at = __call__ (sliceable_a.transpose, sliceable_a);
var slice_at = __getslice__ (sliceable_at, 1, null, 1);
};
__pragma__ ('<use>' +
'numscrypt' +
'</use>')
__pragma__ ('<all>')
__all__.__name__ = __name__;
__all__.run = run;
__pragma__ ('</all>')
}
}
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
__nest__ (
__all__,
'module_fft', {
__all__: {
__inited__: false,
__init__: function (__all__) {
var __name__ = 'module_fft';
var sin = __init__ (__world__.math).sin;
var cos = __init__ (__world__.math).cos;
var pi = __init__ (__world__.math).pi;
var transpiled = __envir__.executor_name == __envir__.transpiler_name;
if (__envir__.executor_name == __envir__.transpiler_name) {
var num = __init__ (__world__.numscrypt);
var fft = __init__ (__world__.numscrypt.fft);
}
var fSample = 4096;
var tTotal = 2;
var fSin = 30;
var fCos = 50;
var getNow = function () {
return new Date ();
};
var tCurrent = function (iCurrent) {
return iCurrent / fSample;
};
var run = function (autoTester) {
var delta = __add__ (0.001, complex (0, 0.001));
autoTester.check ('<br>------ 1D ------<br>');
var cut = 102;
autoTester.check ('Samples computed: {}<br>'.format (tTotal * fSample));
autoTester.check ('Samples shown: {}<br>'.format (cut));
var orig = num.array ((function () {
var __accu0__ = [];
for (var t of (function () {
var __accu1__ = [];
for (var iSample = 0; iSample < tTotal * fSample; iSample++) {
__accu1__.append (iSample / fSample);
}
return __accu1__;
}) ()) {
__accu0__.append (complex ((0.3 + sin (((2 * pi) * fSin) * t)) + 0.5 * cos (((2 * pi) * fCos) * t), 0));
}
return __accu0__;
}) (), 'complex128');
__call__ (autoTester.check, autoTester, 'Original samples', __getslice__ (__call__ (__call__ (num.round, num, __add__ (orig, delta), 3).tolist, __call__ (num.round, num, __add__ (orig, delta), 3)), 0, cut, 1), '<br>');
if (transpiled) {
var timeStartFft = __call__ (getNow, null);
}
var freqs = __call__ (fft.fft, fft, orig);
if (transpiled) {
var timeStopFft = __call__ (getNow, null);
}
__call__ (autoTester.check, autoTester, 'Frequencies', __getslice__ (__call__ (__call__ (num.round, num, __add__ (freqs, delta), 3).tolist, __call__ (num.round, num, __add__ (freqs, delta), 3)), 0, cut, 1), '<br>');
if (transpiled) {
var timeStartIfft = __call__ (getNow, null);
}
var reconstr = __call__ (fft.ifft, fft, freqs);
if (transpiled) {
var timeStopIfft = __call__ (getNow, null);
}
__call__ (autoTester.check, autoTester, 'Reconstructed samples', __getslice__ (__call__ (__call__ (num.round, num, __add__ (reconstr, delta), 3).tolist, __call__ (num.round, num, __add__ (reconstr, delta), 3)), 0, cut, 1), '<br>');
if (transpiled) {
print ('FFT for {} samples took {} ms'.format (tTotal * fSample, timeStopFft - timeStartFft));
print ('IFFT for {} samples took {} ms'.format (tTotal * fSample, timeStopIfft - timeStartIfft));
}
autoTester.check ('<br>------ 2D ------<br>');
var orig2 = __call__ (num.zeros, num, tuple ([128, 128]), 'complex128');
orig2.__setitem__ ([tuple ([32, 96, 1]), tuple ([32, 96, 1])], __call__ (num.ones, num, tuple ([64, 64]), 'complex128'));
__call__ (autoTester.check, autoTester, 'Original samples', __call__ (__call__ (num.round, num, __add__ (orig2, delta), 3).__getitem__ ([tuple ([64, 68, 1]), tuple ([16, 112, 1])]).tolist, __call__ (num.round, num, __add__ (orig2, delta), 3).__getitem__ ([tuple ([64, 68, 1]), tuple ([16, 112, 1])])), '<br>');
if (transpiled) {
var timeStartFft = __call__ (getNow, null);
}
var freqs2 = __call__ (fft.fft2, fft, orig2);
if (transpiled) {
var timeStopFft = __call__ (getNow, null);
}
__call__ (autoTester.check, autoTester, 'Frequencies', __call__ (__call__ (num.round, num, __add__ (freqs2, delta), 3).__getitem__ ([tuple ([64, 68, 1]), tuple ([16, 112, 1])]).tolist, __call__ (num.round, num, __add__ (freqs2, delta), 3).__getitem__ ([tuple ([64, 68, 1]), tuple ([16, 112, 1])])), '<br>');
if (transpiled) {
var timeStartIfft = __call__ (getNow, null);
}
var reconstr2 = __call__ (fft.ifft2, fft, freqs2);
if (transpiled) {
var timeStopIfft = __call__ (getNow, null);
}
if (transpiled) {
__call__ (print, null, __call__ ('FFT2 for {} samples took {} ms'.format, 'FFT2 for {} samples took {} ms', orig2.size, __sub__ (timeStopFft, timeStartFft)));
__call__ (print, null, __call__ ('IFFT2 for {} samples took {} ms'.format, 'IFFT2 for {} samples took {} ms', orig2.size, __sub__ (timeStopIfft, timeStartIfft)));
}
__call__ (autoTester.check, autoTester, 'Reconstructed samples', __call__ (__call__ (num.round, num, __add__ (reconstr2, delta), 3).__getitem__ ([tuple ([64, 68, 1]), tuple ([16, 112, 1])]).tolist, __call__ (num.round, num, __add__ (reconstr2, delta), 3).__getitem__ ([tuple ([64, 68, 1]), tuple ([16, 112, 1])])), '<br>');
};
__pragma__ ('<use>' +
'math' +
'numscrypt' +
'numscrypt.fft' +
'</use>')
__pragma__ ('<all>')
__all__.__name__ = __name__;
__all__.cos = cos;
__all__.fCos = fCos;
__all__.fSample = fSample;
__all__.fSin = fSin;
__all__.getNow = getNow;
__all__.pi = pi;
__all__.run = run;
__all__.sin = sin;
__all__.tCurrent = tCurrent;
__all__.tTotal = tTotal;
__all__.transpiled = transpiled;
__pragma__ ('</all>')
}
}
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
__nest__ (
__all__,
'module_linalg', {
__all__: {
__inited__: false,
__init__: function (__all__) {
var __name__ = 'module_linalg';
if (__envir__.executor_name == __envir__.transpiler_name) {
var num = __init__ (__world__.numscrypt);
var linalg = __init__ (__world__.numscrypt.linalg);
}
var run = function (autoTester) {
var r = num.array (list ([list ([2.12, -(2.11), -(1.23)]), list ([2.31, 1.14, 3.15]), list ([1.13, 1.98, 2.81])]));
autoTester.check ('Matrix r', num.round (r, 2).tolist (), '<br>');
var ri = linalg.inv (r);
autoTester.check ('Matrix ri', num.round (ri, 2).tolist (), '<br>');
var rid = __matmul__ (r, ri);
autoTester.check ('r @ ri', (function () {
var __accu0__ = [];
for (var row of rid.tolist ()) {
__accu0__.append ((function () {
var __accu1__ = [];
for (var elem of row) {
__accu1__.append (int (round (elem)));
}
return __accu1__;
}) ());
}
return __accu0__;
}) (), '<br>');
var delta = 0.001;
__call__ (autoTester.check, autoTester, 'r * r', __call__ (__call__ (num.round, num, __add__ (__mul__ (r, r), delta), 3).tolist, __call__ (num.round, num, __add__ (__mul__ (r, r), delta), 3)), '<br>');
__call__ (autoTester.check, autoTester, 'r / r', __call__ (__call__ (num.round, num, __add__ (__truediv__ (r, r), delta), 3).tolist, __call__ (num.round, num, __add__ (__truediv__ (r, r), delta), 3)), '<br>');
__call__ (autoTester.check, autoTester, 'r + r', __call__ (__call__ (num.round, num, __add__ (__add__ (r, r), delta), 3).tolist, __call__ (num.round, num, __add__ (__add__ (r, r), delta), 3)), '<br>');
__call__ (autoTester.check, autoTester, 'r - r', __call__ (__call__ (num.round, num, __add__ (__sub__ (r, r), delta), 3).tolist, __call__ (num.round, num, __add__ (__sub__ (r, r), delta), 3)), '<br>');
var c = __call__ (num.array, num, list ([list ([__sub__ (2.12, complex (0, 3.15)), __neg__ (2.11), __neg__ (1.23)]), list ([2.31, 1.14, __add__ (3.15, complex (0, 2.75))]), list ([1.13, __sub__ (1.98, complex (0, 4.33)), 2.81])]), 'complex128');
autoTester.check ('Matrix c', num.round (c, 2).tolist (), '<br>');
var ci = linalg.inv (c);
autoTester.check ('Matrix ci', num.round (ci, 2).tolist (), '<br>');
var cid = __matmul__ (c, ci);
var delta = __add__ (0.001, complex (0, 0.001));
__call__ (autoTester.check, autoTester, 'c * c', __call__ (__call__ (num.round, num, __add__ (__mul__ (c, c), delta), 3).tolist, __call__ (num.round, num, __add__ (__mul__ (c, c), delta), 3)), '<br>');
__call__ (autoTester.check, autoTester, 'c / c', __call__ (__call__ (num.round, num, __add__ (__truediv__ (c, c), delta), 3).tolist, __call__ (num.round, num, __add__ (__truediv__ (c, c), delta), 3)), '<br>');
__call__ (autoTester.check, autoTester, 'c + c', __call__ (__call__ (num.round, num, __add__ (__add__ (c, c), delta), 3).tolist, __call__ (num.round, num, __add__ (__add__ (c, c), delta), 3)), '<br>');
__call__ (autoTester.check, autoTester, 'c - c', __call__ (__call__ (num.round, num, __add__ (__sub__ (c, c), delta), 3).tolist, __call__ (num.round, num, __add__ (__sub__ (c, c), delta), 3)), '<br>');
};
__pragma__ ('<use>' +
'numscrypt' +
'numscrypt.linalg' +
'</use>')
__pragma__ ('<all>')
__all__.__name__ = __name__;
__all__.run = run;
__pragma__ ('</all>')
}
}
}
);
Loading

0 comments on commit abd2c05

Please sign in to comment.