Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
6ebe0863
Commit
6ebe0863
authored
Jun 29, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document these changes
parent
5d297233
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
docs/type_conversions.md
docs/type_conversions.md
+25
-9
No files found.
docs/type_conversions.md
View file @
6ebe0863
...
...
@@ -26,15 +26,31 @@ Python. The values are copied and any connection to the original object is lost.
|
`list`
,
`tuple`
|
`Array`
|
|
`dict`
|
`Object`
|
Additionally, Python
`bytes`
and
`buffer`
objects are converted to/from Javascript
`Uint8ClampedArray`
typed arrays. In this case, however, the underlying data is
not copied, and is shared between the Python and Javascript sides. This makes
passing raw memory between the languages (which in practice can be quite large)
very efficient.
Aside: This is the technology on which matplotlib images are passed to
Javascript to render in a canvas, and will be the basis of sharing Numpy arrays
with n-dimensional array data structures in Javascript.
## Typed arrays
Javascript typed arrays (Int8Array and friends) are converted to Python
`memoryviews`
. This happens with a single binary memory copy (since Python can't
access arrays on the Javascript heap), and the data type is preserved. This
makes it easy to correctly convert it to a Numpy array using
`numpy.asarray`
:
```
javascript
array
=
Float32Array
([
1
,
2
,
3
])
```
```
python
from
js
import
array
import
numpy
as
np
numpy_array
=
np
.
asarray
(
array
)
```
Python
`bytes`
and
`buffer`
objects are converted to Javascript as
`Uint8ClampedArray`
s, without any memory copy at all, and is thus very
efficient, but be aware that any changes to the buffer will be reflected in both
places.
Numpy arrays are currently converted to Javascript as nested (regular) Arrays. A
more efficient method will probably emerge as we decide on an ndarray
implementation for Javascript.
## Class instances
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment