Safely access data in PyUntypedArray
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- numpy, rust
- Domain
- api, backend-api-design, data
Research direction
Start at PyUntypedArrayMethods::as_array_ptr and read the Rust pointer-to-reference conversion documentation cited in the issue. Determine the existing pointer’s safety guarantees and evaluate the proposed bytes accessor, including what documentation or tests are needed to show that callers can access the data safely without their own unsafe code.
Written by the indexing model from the issue text.
Description
PyUntypedArrayMethods::as_array_ptr doesn’t describe under which circumstances the returned pointer is convertible into a reference.
Since the requirements are rather hairy, it would be great to have a way to access the data safely without going through unsafe. Would it e.g. be possible to have this?
trait PyUntypedArrayMethods<'py> {
...
fn bytes<'a>(&'a self) -> &'a [u8] {
let ptr = self.as_array_ptr();
let n_bytes = self.len() * self.dtype().itemsize();
unsafe {
let p = (*ptr).data.cast();
slice::from_raw_parts(p, n_bytes)
}
}
}
Because we currently implement this ourselves, but without any of the aforementioned safety information, we can’t really be sure if it’s safe.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 141
- Avg merge
- 16m
- Merged PRs (30d)
- 3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PyO3/rust-numpy
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
PyO3/rust-numpy#565 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
PyO3/rust-numpy#563 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
PyO3/rust-numpy#557 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
PyO3/rust-numpy#547 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 20/100
PyO3/rust-numpy#535 ·
Similar issues
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
n0-computer/iroh#4550 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
paritytech/zombienet-sdk#591 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
farion1231/cc-switch#7638 · 1 comment ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100