2018-03-30 14:51:13 +00:00
|
|
|
def test_numpy(selenium):
|
2018-05-04 17:09:32 +00:00
|
|
|
selenium.load_package("numpy")
|
2018-03-30 14:51:13 +00:00
|
|
|
selenium.run("import numpy")
|
|
|
|
x = selenium.run("numpy.zeros((32, 64))")
|
|
|
|
assert len(x) == 32
|
|
|
|
assert all(len(y) == 64 for y in x)
|
|
|
|
for y in x:
|
|
|
|
assert all(z == 0 for z in y)
|
2018-06-29 20:18:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_typed_arrays(selenium):
|
|
|
|
selenium.load_package("numpy")
|
|
|
|
selenium.run("import numpy")
|
|
|
|
for (jstype, npytype) in (
|
|
|
|
('Int8Array', 'int8'),
|
|
|
|
('Uint8Array', 'uint8'),
|
|
|
|
('Uint8ClampedArray', 'uint8'),
|
|
|
|
('Int16Array', 'int16'),
|
|
|
|
('Uint16Array', 'uint16'),
|
|
|
|
('Int32Array', 'int32'),
|
|
|
|
('Uint32Array', 'uint32'),
|
|
|
|
('Float32Array', 'float32'),
|
|
|
|
('Float64Array', 'float64')):
|
|
|
|
print(jstype, npytype)
|
|
|
|
selenium.run_js(
|
|
|
|
f'window.array = new {jstype}([1, 2, 3, 4]);\n')
|
|
|
|
assert selenium.run(
|
|
|
|
'from js import array\n'
|
|
|
|
'npyarray = numpy.asarray(array)\n'
|
|
|
|
f'npyarray.dtype.name == "{npytype}" '
|
|
|
|
'and npyarray == [1, 2, 3, 4]')
|