Comments (5)
Hmm, it seems that the numpy buffer has a format string of "O". The Buffer protocol specification says the format string is
A NULL-terminated string in struct-module-style syntax describing the contents of a single item. If this is NULL, "B" (unsigned bytes) is assumed.
The format characters listed in the struct module table include "P"
for void*
but not "O"
for PyObject*
. So it seems that numpy uses some nonstandard extensions to the python buffer protocol. @mattip @charris is there a place where this is documented? It would be helpful for consumers of the buffer protocol to have a single reference for the set of possible format strings that "accepted, well-behaving" implementations of bf_getbuffer
can produce...
I see that in addition to "O"
there are "Zf"
, "Zd"
, and "Zg"
for complex floating point types. It's not obvious how we would handle those anyways other than making a clearer error message.
from pyodide.
There is some documentation in the array interface page, but I think this is not the whole story. As you point out, Zf
, Zd
and Zg
do not appear there (in fact, c
is character and not complex as appears there), and the np.structured arrays minilanguage is, as far as I could tell, not documented. A few examples:
>>> memoryview(np.ones([10], dtype=[('a', float), ('b', int)])).format
'T{d:a:l:b:}'
>>> memoryview(np.ones([10], dtype=[('a', float), ('b', int, [10,10])])).format
'T{d:a:(10,10)l:b:}'
from pyodide.
Ah PEP 3118 has more:
https://peps.python.org/pep-3118/
from pyodide.
Oh gross pep3118 was never fully implemented and in fact it is not entirely well specified:
python/cpython#47382
The new features of the struct-string syntax are so different that I think
we need to specify a grammar. I think it will clarify some of the open
questions.
from pyodide.
Opened a question on the status of PEP 3118:
https://discuss.python.org/t/question-pep-3118-format-strings-and-the-buffer-protocol/31264
from pyodide.
Related Issues (20)
- Add esbuild-py HOT 4
- Add `PyMuPDF` package
- runPython return missing
- cmake -E capabilities is broken HOT 1
- Release 0.26.0 HOT 5
- datasets (huggingface) HOT 6
- Cannot create a WebGL2 context when using SDL HOT 3
- request to add pandasai HOT 1
- request to add llama-index
- request to add langchain HOT 1
- request to add Boto3 HOT 4
- fastobo
- loadPackage() not to access the file system if the cache already exists HOT 2
- cvxpy-base 1.4.3 HOT 2
- html5_canvas_backend no longer works. HOT 1
- RFC Package unvendored stdlibs to sdist / wheel? HOT 3
- `make` in docker container `pyodide/pyodide-env` fails with `could not create work tree dir 'emsdk'` HOT 8
- DOM types in pyodide lead to build issues with Angular and typescript. HOT 3
- Request add to section-properies package
- feat: Resolving CORS Restrictions in Node.js HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyodide.