Skip to content

Commit f8522cf

Browse files
committed
Merge branch '0.15.x'
2 parents c66d408 + e080d62 commit f8522cf

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "ndarray"
4-
version = "0.15.5"
4+
version = "0.15.6"
55
edition = "2018"
66
rust-version = "1.51"
77
authors = [

RELEASES.md

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
Version 0.15.6 (2022-07-30)
2+
===========================
3+
4+
New features
5+
------------
6+
7+
- Add `get_ptr` and `get_mut_ptr` methods for getting an element's pointer from
8+
an index, by [@adamreichold].
9+
10+
https://github.com/rust-ndarray/ndarray/pull/1151
11+
12+
Other changes
13+
-------------
14+
15+
- Various fixes to resolve compiler and Clippy warnings/errors, by [@aganders3]
16+
and [@jturner314].
17+
18+
https://github.com/rust-ndarray/ndarray/pull/1171
19+
20+
- Fix description of `stack!` in quick start docs, by [@jturner314]. Thanks to
21+
[@HyeokSuLee] for pointing out the issue.
22+
23+
https://github.com/rust-ndarray/ndarray/pull/1156
24+
25+
- Add MSRV to `Cargo.toml`.
26+
27+
https://github.com/rust-ndarray/ndarray/pull/1191
28+
29+
130
Version 0.15.5 (2022-07-30)
231
===========================
332

@@ -1561,6 +1590,8 @@ Earlier releases
15611590
- Starting point for evolution to come
15621591

15631592

1593+
[@adamreichold]: https://github.com/adamreichold
1594+
[@aganders3]: https://github.com/aganders3
15641595
[@bluss]: https://github.com/bluss
15651596
[@jturner314]: https://github.com/jturner314
15661597
[@LukeMathWalker]: https://github.com/LukeMathWalker
@@ -1575,6 +1606,7 @@ Earlier releases
15751606
[@ethanhs]: https://github.com/ethanhs
15761607
[@d-dorazio]: https://github.com/d-dorazio
15771608
[@Eijebong]: https://github.com/Eijebong
1609+
[@HyeokSuLee]: https://github.com/HyeokSuLee
15781610
[@insideoutclub]: https://github.com/insideoutclub
15791611
[@JP-Ellis]: https://github.com/JP-Ellis
15801612
[@jimblandy]: https://github.com/jimblandy

src/impl_methods.rs

+34-4
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,26 @@ where
732732
/// ```
733733
pub fn get<I>(&self, index: I) -> Option<&A>
734734
where
735-
I: NdIndex<D>,
736735
S: Data,
736+
I: NdIndex<D>,
737737
{
738738
unsafe { self.get_ptr(index).map(|ptr| &*ptr) }
739739
}
740740

741-
pub(crate) fn get_ptr<I>(&self, index: I) -> Option<*const A>
741+
/// Return a raw pointer to the element at `index`, or return `None`
742+
/// if the index is out of bounds.
743+
///
744+
/// ```
745+
/// use ndarray::arr2;
746+
///
747+
/// let a = arr2(&[[1., 2.], [3., 4.]]);
748+
///
749+
/// let v = a.raw_view();
750+
/// let p = a.get_ptr((0, 1)).unwrap();
751+
///
752+
/// assert_eq!(unsafe { *p }, 2.);
753+
/// ```
754+
pub fn get_ptr<I>(&self, index: I) -> Option<*const A>
742755
where
743756
I: NdIndex<D>,
744757
{
@@ -755,10 +768,27 @@ where
755768
S: DataMut,
756769
I: NdIndex<D>,
757770
{
758-
unsafe { self.get_ptr_mut(index).map(|ptr| &mut *ptr) }
771+
unsafe { self.get_mut_ptr(index).map(|ptr| &mut *ptr) }
759772
}
760773

761-
pub(crate) fn get_ptr_mut<I>(&mut self, index: I) -> Option<*mut A>
774+
/// Return a raw pointer to the element at `index`, or return `None`
775+
/// if the index is out of bounds.
776+
///
777+
/// ```
778+
/// use ndarray::arr2;
779+
///
780+
/// let mut a = arr2(&[[1., 2.], [3., 4.]]);
781+
///
782+
/// let v = a.raw_view_mut();
783+
/// let p = a.get_mut_ptr((0, 1)).unwrap();
784+
///
785+
/// unsafe {
786+
/// *p = 5.;
787+
/// }
788+
///
789+
/// assert_eq!(a.get((0, 1)), Some(&5.));
790+
/// ```
791+
pub fn get_mut_ptr<I>(&mut self, index: I) -> Option<*mut A>
762792
where
763793
S: RawDataMut,
764794
I: NdIndex<D>,

src/impl_views/indexing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ where
164164
fn index(mut self, index: I) -> &'a mut A {
165165
debug_bounds_check!(self, index);
166166
unsafe {
167-
match self.get_ptr_mut(index) {
167+
match self.get_mut_ptr(index) {
168168
Some(ptr) => &mut *ptr,
169169
None => array_out_of_bounds(),
170170
}
@@ -182,7 +182,7 @@ where
182182
fn get(mut self, index: I) -> Option<&'a mut A> {
183183
debug_bounds_check!(self, index);
184184
unsafe {
185-
match self.get_ptr_mut(index) {
185+
match self.get_mut_ptr(index) {
186186
Some(ptr) => Some(&mut *ptr),
187187
None => None,
188188
}

0 commit comments

Comments
 (0)