Skip to content

Change ArrayBase.ptr to NonNull type #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -44,11 +44,11 @@ blas-src = { version = "0.2.0", optional = true, default-features = false }
matrixmultiply = { version = "0.2.0" }
# Use via the `serde-1` crate feature!
serde = { version = "1.0", optional = true }
rawpointer = { version = "0.2" }

[dev-dependencies]
defmac = "0.2"
quickcheck = { version = "0.8", default-features = false }
rawpointer = "0.1"
approx = "0.3.2"
itertools = { version = "0.8.0", default-features = false, features = ["use_std"] }

2 changes: 1 addition & 1 deletion src/arraytraits.rs
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ where
fn index(&self, index: I) -> &S::Elem {
debug_bounds_check!(self, index);
unsafe {
&*self.ptr.offset(
&*self.ptr.as_ptr().offset(
index
.index_checked(&self.dim, &self.strides)
.unwrap_or_else(|| array_out_of_bounds()),
42 changes: 23 additions & 19 deletions src/data_traits.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,10 @@

//! The data (inner representation) traits for ndarray
use crate::extension::nonnull::nonnull_from_vec_data;
use rawpointer::PointerExt;
use std::mem::{self, size_of};
use std::ptr::NonNull;
use std::sync::Arc;

use crate::{
@@ -67,14 +70,14 @@ pub unsafe trait RawDataMut: RawData {
pub unsafe trait RawDataClone: RawData {
#[doc(hidden)]
/// Unsafe because, `ptr` must point inside the current storage.
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem);
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>);

#[doc(hidden)]
unsafe fn clone_from_with_ptr(
&mut self,
other: &Self,
ptr: *mut Self::Elem,
) -> *mut Self::Elem {
ptr: NonNull<Self::Elem>,
) -> NonNull<Self::Elem> {
let (data, ptr) = other.clone_with_ptr(ptr);
*self = data;
ptr
@@ -148,7 +151,7 @@ unsafe impl<A> RawData for RawViewRepr<*const A> {
}

unsafe impl<A> RawDataClone for RawViewRepr<*const A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>) {
(*self, ptr)
}
}
@@ -177,7 +180,7 @@ unsafe impl<A> RawDataMut for RawViewRepr<*mut A> {
}

unsafe impl<A> RawDataClone for RawViewRepr<*mut A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>) {
(*self, ptr)
}
}
@@ -217,13 +220,13 @@ where
let rcvec = &mut self_.data.0;
let a_size = mem::size_of::<A>() as isize;
let our_off = if a_size != 0 {
(self_.ptr as isize - rcvec.as_ptr() as isize) / a_size
(self_.ptr.as_ptr() as isize - rcvec.as_ptr() as isize) / a_size
} else {
0
};
let rvec = Arc::make_mut(rcvec);
unsafe {
self_.ptr = rvec.as_mut_ptr().offset(our_off);
self_.ptr = nonnull_from_vec_data(rvec).offset(our_off);
}
}

@@ -252,7 +255,7 @@ unsafe impl<A> Data for OwnedArcRepr<A> {
unsafe impl<A> DataMut for OwnedArcRepr<A> where A: Clone {}

unsafe impl<A> RawDataClone for OwnedArcRepr<A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>) {
// pointer is preserved
(self.clone(), ptr)
}
@@ -298,11 +301,12 @@ unsafe impl<A> RawDataClone for OwnedRepr<A>
where
A: Clone,
{
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>) {
let mut u = self.clone();
let mut new_ptr = u.0.as_mut_ptr();
let mut new_ptr = nonnull_from_vec_data(&mut u.0);
if size_of::<A>() != 0 {
let our_off = (ptr as isize - self.0.as_ptr() as isize) / mem::size_of::<A>() as isize;
let our_off =
(ptr.as_ptr() as isize - self.0.as_ptr() as isize) / mem::size_of::<A>() as isize;
new_ptr = new_ptr.offset(our_off);
}
(u, new_ptr)
@@ -311,15 +315,15 @@ where
unsafe fn clone_from_with_ptr(
&mut self,
other: &Self,
ptr: *mut Self::Elem,
) -> *mut Self::Elem {
ptr: NonNull<Self::Elem>,
) -> NonNull<Self::Elem> {
let our_off = if size_of::<A>() != 0 {
(ptr as isize - other.0.as_ptr() as isize) / mem::size_of::<A>() as isize
(ptr.as_ptr() as isize - other.0.as_ptr() as isize) / mem::size_of::<A>() as isize
} else {
0
};
self.0.clone_from(&other.0);
self.0.as_mut_ptr().offset(our_off)
nonnull_from_vec_data(&mut self.0).offset(our_off)
}
}

@@ -342,7 +346,7 @@ unsafe impl<'a, A> Data for ViewRepr<&'a A> {
}

unsafe impl<'a, A> RawDataClone for ViewRepr<&'a A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>) {
(*self, ptr)
}
}
@@ -469,7 +473,7 @@ unsafe impl<'a, A> RawDataClone for CowRepr<'a, A>
where
A: Clone,
{
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
unsafe fn clone_with_ptr(&self, ptr: NonNull<Self::Elem>) -> (Self, NonNull<Self::Elem>) {
match self {
CowRepr::View(view) => {
let (new_view, ptr) = view.clone_with_ptr(ptr);
@@ -486,8 +490,8 @@ where
unsafe fn clone_from_with_ptr(
&mut self,
other: &Self,
ptr: *mut Self::Elem,
) -> *mut Self::Elem {
ptr: NonNull<Self::Elem>,
) -> NonNull<Self::Elem> {
match (&mut *self, other) {
(CowRepr::View(self_), CowRepr::View(other)) => self_.clone_from_with_ptr(other, ptr),
(CowRepr::Owned(self_), CowRepr::Owned(other)) => self_.clone_from_with_ptr(other, ptr),
11 changes: 11 additions & 0 deletions src/extension.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2019 bluss and ndarray developers.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Extension traits and utility functions for types from outside ndarray
pub(crate) mod nonnull;
18 changes: 18 additions & 0 deletions src/extension/nonnull.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::ptr::NonNull;

/// Return a NonNull<T> pointer to the vector's data
pub(crate) fn nonnull_from_vec_data<T>(v: &mut Vec<T>) -> NonNull<T> {
// this pointer is guaranteed to be non-null
unsafe { NonNull::new_unchecked(v.as_mut_ptr()) }
}

/// Converts `ptr` to `NonNull<T>`
///
/// Safety: `ptr` *must* be non-null.
/// This is checked with a debug assertion, and will panic if this is not true,
/// but treat this as an unconditional conversion.
#[inline]
pub(crate) unsafe fn nonnull_debug_checked_from_ptr<T>(ptr: *mut T) -> NonNull<T> {
debug_assert!(!ptr.is_null());
NonNull::new_unchecked(ptr)
}
1 change: 1 addition & 0 deletions src/impl_clone.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::imp_prelude::*;
use crate::RawDataClone;

3 changes: 2 additions & 1 deletion src/impl_constructors.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ use num_traits::{Float, One, Zero};

use crate::dimension;
use crate::error::{self, ShapeError};
use crate::extension::nonnull::nonnull_from_vec_data;
use crate::imp_prelude::*;
use crate::indexes;
use crate::indices;
@@ -422,7 +423,7 @@ where
// debug check for issues that indicates wrong use of this constructor
debug_assert!(dimension::can_index_slice(&v, &dim, &strides).is_ok());
ArrayBase {
ptr: v.as_mut_ptr(),
ptr: nonnull_from_vec_data(&mut v),
data: DataOwned::new(v),
strides,
dim,
36 changes: 20 additions & 16 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ use std::ptr as std_ptr;
use std::slice;

use itertools::{izip, zip};
use rawpointer::PointerExt;

use crate::imp_prelude::*;

@@ -138,7 +139,7 @@ where
S: Data,
{
debug_assert!(self.pointer_is_inbounds());
unsafe { ArrayView::new_(self.ptr, self.dim.clone(), self.strides.clone()) }
unsafe { ArrayView::new_(self.ptr.as_ptr(), self.dim.clone(), self.strides.clone()) }
}

/// Return a read-write view of the array
@@ -147,7 +148,7 @@ where
S: DataMut,
{
self.ensure_unique();
unsafe { ArrayViewMut::new_(self.ptr, self.dim.clone(), self.strides.clone()) }
unsafe { ArrayViewMut::new_(self.ptr.as_ptr(), self.dim.clone(), self.strides.clone()) }
}

/// Return an uniquely owned copy of the array.
@@ -506,7 +507,7 @@ where
let ptr = self.ptr;
index
.index_checked(&self.dim, &self.strides)
.map(move |offset| unsafe { ptr.offset(offset) as *const _ })
.map(move |offset| unsafe { ptr.as_ptr().offset(offset) as *const _ })
}

/// Return a mutable reference to the element at `index`, or return `None`
@@ -545,7 +546,7 @@ where
{
arraytraits::debug_bounds_check(self, &index);
let off = index.index_unchecked(&self.strides);
&*self.ptr.offset(off)
&*self.ptr.as_ptr().offset(off)
}

/// Perform *unchecked* array indexing.
@@ -563,7 +564,7 @@ where
debug_assert!(self.data.is_unique());
arraytraits::debug_bounds_check(self, &index);
let off = index.index_unchecked(&self.strides);
&mut *self.ptr.offset(off)
&mut *self.ptr.as_ptr().offset(off)
}

/// Swap elements at indices `index1` and `index2`.
@@ -599,7 +600,10 @@ where
arraytraits::debug_bounds_check(self, &index2);
let off1 = index1.index_unchecked(&self.strides);
let off2 = index2.index_unchecked(&self.strides);
std_ptr::swap(self.ptr.offset(off1), self.ptr.offset(off2));
std_ptr::swap(
self.ptr.as_ptr().offset(off1),
self.ptr.as_ptr().offset(off2),
);
}

// `get` for zero-dimensional arrays
@@ -1293,7 +1297,7 @@ where
/// where *d* is `self.ndim()`.
#[inline(always)]
pub fn as_ptr(&self) -> *const A {
self.ptr
self.ptr.as_ptr() as *const A
}

/// Return a mutable pointer to the first element in the array.
@@ -1303,13 +1307,13 @@ where
S: RawDataMut,
{
self.try_ensure_unique(); // for RcArray
self.ptr
self.ptr.as_ptr()
}

/// Return a raw view of the array.
#[inline]
pub fn raw_view(&self) -> RawArrayView<A, D> {
unsafe { RawArrayView::new_(self.ptr, self.dim.clone(), self.strides.clone()) }
unsafe { RawArrayView::new_(self.ptr.as_ptr(), self.dim.clone(), self.strides.clone()) }
}

/// Return a raw mutable view of the array.
@@ -1319,7 +1323,7 @@ where
S: RawDataMut,
{
self.try_ensure_unique(); // for RcArray
unsafe { RawArrayViewMut::new_(self.ptr, self.dim.clone(), self.strides.clone()) }
unsafe { RawArrayViewMut::new_(self.ptr.as_ptr(), self.dim.clone(), self.strides.clone()) }
}

/// Return the array’s data as a slice, if it is contiguous and in standard order.
@@ -1332,7 +1336,7 @@ where
S: Data,
{
if self.is_standard_layout() {
unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) }
unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) }
} else {
None
}
@@ -1346,7 +1350,7 @@ where
{
if self.is_standard_layout() {
self.ensure_unique();
unsafe { Some(slice::from_raw_parts_mut(self.ptr, self.len())) }
unsafe { Some(slice::from_raw_parts_mut(self.ptr.as_ptr(), self.len())) }
} else {
None
}
@@ -1364,7 +1368,7 @@ where
S: Data,
{
if self.is_contiguous() {
unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) }
unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) }
} else {
None
}
@@ -1378,7 +1382,7 @@ where
{
if self.is_contiguous() {
self.ensure_unique();
unsafe { Some(slice::from_raw_parts_mut(self.ptr, self.len())) }
unsafe { Some(slice::from_raw_parts_mut(self.ptr.as_ptr(), self.len())) }
} else {
None
}
@@ -1616,7 +1620,7 @@ where
Some(st) => st,
None => return None,
};
unsafe { Some(ArrayView::new_(self.ptr, dim, broadcast_strides)) }
unsafe { Some(ArrayView::new_(self.ptr.as_ptr(), dim, broadcast_strides)) }
}

/// Swap axes `ax` and `bx`.
@@ -1843,7 +1847,7 @@ where
Some(slc) => {
let ptr = slc.as_ptr() as *mut A;
let end = unsafe { ptr.add(slc.len()) };
self.ptr >= ptr && self.ptr <= end
self.ptr.as_ptr() >= ptr && self.ptr.as_ptr() <= end
}
}
}
2 changes: 1 addition & 1 deletion src/impl_owned_array.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ impl<A> Array<A, Ix0> {
// (This is necessary because the element in the array might not be
// the first element in the `Vec`, such as if the array was created
// by `array![1, 2, 3, 4].slice_move(s![2])`.)
let first = self.ptr as usize;
let first = self.ptr.as_ptr() as usize;
let base = self.data.0.as_ptr() as usize;
let index = (first - base) / size;
debug_assert_eq!((first - base) % size, 0);
23 changes: 12 additions & 11 deletions src/impl_raw_views.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::dimension::{self, stride_offset};
use crate::extension::nonnull::nonnull_debug_checked_from_ptr;
use crate::imp_prelude::*;
use crate::{is_aligned, StrideShape};

@@ -14,7 +15,7 @@ where
pub(crate) unsafe fn new_(ptr: *const A, dim: D, strides: D) -> Self {
RawArrayView {
data: RawViewRepr::new(),
ptr: ptr as *mut A,
ptr: nonnull_debug_checked_from_ptr(ptr as *mut _),
dim,
strides,
}
@@ -75,7 +76,7 @@ where
/// ensure that all of the data is valid and choose the correct lifetime.
#[inline]
pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> {
ArrayView::new_(self.ptr, self.dim, self.strides)
ArrayView::new_(self.ptr.as_ptr(), self.dim, self.strides)
}

/// Split the array view along `axis` and return one array pointer strictly
@@ -84,13 +85,13 @@ where
/// **Panics** if `axis` or `index` is out of bounds.
pub fn split_at(self, axis: Axis, index: Ix) -> (Self, Self) {
assert!(index <= self.len_of(axis));
let left_ptr = self.ptr;
let left_ptr = self.ptr.as_ptr();
let right_ptr = if index == self.len_of(axis) {
self.ptr
self.ptr.as_ptr()
} else {
let offset = stride_offset(index, self.strides.axis(axis));
// The `.offset()` is safe due to the guarantees of `RawData`.
unsafe { self.ptr.offset(offset) }
unsafe { self.ptr.as_ptr().offset(offset) }
};

let mut dim_left = self.dim.clone();
@@ -118,7 +119,7 @@ where
pub(crate) unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self {
RawArrayViewMut {
data: RawViewRepr::new(),
ptr,
ptr: nonnull_debug_checked_from_ptr(ptr),
dim,
strides,
}
@@ -175,7 +176,7 @@ where
/// Converts to a non-mutable `RawArrayView`.
#[inline]
pub(crate) fn into_raw_view(self) -> RawArrayView<A, D> {
unsafe { RawArrayView::new_(self.ptr, self.dim, self.strides) }
unsafe { RawArrayView::new_(self.ptr.as_ptr(), self.dim, self.strides) }
}

/// Converts to a read-only view of the array.
@@ -185,7 +186,7 @@ where
/// ensure that all of the data is valid and choose the correct lifetime.
#[inline]
pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> {
ArrayView::new_(self.ptr, self.dim, self.strides)
ArrayView::new_(self.ptr.as_ptr(), self.dim, self.strides)
}

/// Converts to a mutable view of the array.
@@ -195,7 +196,7 @@ where
/// ensure that all of the data is valid and choose the correct lifetime.
#[inline]
pub unsafe fn deref_into_view_mut<'a>(self) -> ArrayViewMut<'a, A, D> {
ArrayViewMut::new_(self.ptr, self.dim, self.strides)
ArrayViewMut::new_(self.ptr.as_ptr(), self.dim, self.strides)
}

/// Split the array view along `axis` and return one array pointer strictly
@@ -206,8 +207,8 @@ where
let (left, right) = self.into_raw_view().split_at(axis, index);
unsafe {
(
Self::new_(left.ptr, left.dim, left.strides),
Self::new_(right.ptr, right.dim, right.strides),
Self::new_(left.ptr.as_ptr(), left.dim, left.strides),
Self::new_(right.ptr.as_ptr(), right.dim, right.strides),
)
}
}
5 changes: 3 additions & 2 deletions src/impl_views/constructors.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

use crate::dimension;
use crate::error::ShapeError;
use crate::extension::nonnull::nonnull_debug_checked_from_ptr;
use crate::imp_prelude::*;
use crate::{is_aligned, StrideShape};

@@ -219,7 +220,7 @@ where
pub(crate) unsafe fn new_(ptr: *const A, dim: D, strides: D) -> Self {
ArrayView {
data: ViewRepr::new(),
ptr: ptr as *mut A,
ptr: nonnull_debug_checked_from_ptr(ptr as *mut A),
dim,
strides,
}
@@ -242,7 +243,7 @@ where
}
ArrayViewMut {
data: ViewRepr::new(),
ptr,
ptr: nonnull_debug_checked_from_ptr(ptr),
dim,
strides,
}
16 changes: 8 additions & 8 deletions src/impl_views/conversions.rs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ where
#[allow(clippy::wrong_self_convention)]
pub fn into_slice(&self) -> Option<&'a [A]> {
if self.is_standard_layout() {
unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) }
unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) }
} else {
None
}
@@ -45,15 +45,15 @@ where
/// Return `None` otherwise.
pub fn to_slice(&self) -> Option<&'a [A]> {
if self.is_standard_layout() {
unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) }
unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) }
} else {
None
}
}

/// Converts to a raw array view.
pub(crate) fn into_raw_view(self) -> RawArrayView<A, D> {
unsafe { RawArrayView::new_(self.ptr, self.dim, self.strides) }
unsafe { RawArrayView::new_(self.ptr.as_ptr(), self.dim, self.strides) }
}
}

@@ -132,7 +132,7 @@ where
{
#[inline]
pub(crate) fn into_base_iter(self) -> Baseiter<A, D> {
unsafe { Baseiter::new(self.ptr, self.dim, self.strides) }
unsafe { Baseiter::new(self.ptr.as_ptr(), self.dim, self.strides) }
}

#[inline]
@@ -161,17 +161,17 @@ where
{
// Convert into a read-only view
pub(crate) fn into_view(self) -> ArrayView<'a, A, D> {
unsafe { ArrayView::new_(self.ptr, self.dim, self.strides) }
unsafe { ArrayView::new_(self.ptr.as_ptr(), self.dim, self.strides) }
}

/// Converts to a mutable raw array view.
pub(crate) fn into_raw_view_mut(self) -> RawArrayViewMut<A, D> {
unsafe { RawArrayViewMut::new_(self.ptr, self.dim, self.strides) }
unsafe { RawArrayViewMut::new_(self.ptr.as_ptr(), self.dim, self.strides) }
}

#[inline]
pub(crate) fn into_base_iter(self) -> Baseiter<A, D> {
unsafe { Baseiter::new(self.ptr, self.dim, self.strides) }
unsafe { Baseiter::new(self.ptr.as_ptr(), self.dim, self.strides) }
}

#[inline]
@@ -181,7 +181,7 @@ where

pub(crate) fn into_slice_(self) -> Result<&'a mut [A], Self> {
if self.is_standard_layout() {
unsafe { Ok(slice::from_raw_parts_mut(self.ptr, self.len())) }
unsafe { Ok(slice::from_raw_parts_mut(self.ptr.as_ptr(), self.len())) }
} else {
Err(self)
}
4 changes: 2 additions & 2 deletions src/iterators/mod.rs
Original file line number Diff line number Diff line change
@@ -805,7 +805,7 @@ impl<A, D: Dimension> AxisIterCore<A, D> {
stride: v.stride_of(axis),
inner_dim: v.dim.remove_axis(axis),
inner_strides: v.strides.remove_axis(axis),
ptr: v.ptr,
ptr: v.ptr.as_ptr(),
}
}

@@ -1284,7 +1284,7 @@ fn chunk_iter_parts<A, D: Dimension>(
stride,
inner_dim,
inner_strides: v.strides,
ptr: v.ptr,
ptr: v.ptr.as_ptr(),
};

(iter, partial_chunk_index, partial_chunk_dim)
2 changes: 1 addition & 1 deletion src/iterators/windows.rs
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ impl<'a, A, D: Dimension> Windows<'a, A, D> {

unsafe {
Windows {
base: ArrayView::from_shape_ptr(size.clone().strides(a.strides), a.ptr),
base: ArrayView::from_shape_ptr(size.clone().strides(a.strides), a.ptr.as_ptr()),
window,
strides: window_strides,
}
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -153,6 +153,7 @@ pub use crate::free_functions::*;
pub use crate::iterators::iter;

mod error;
mod extension;
mod geomspace;
mod indexes;
mod iterators;
@@ -1217,7 +1218,7 @@ where
data: S,
/// A non-null and aligned pointer into the buffer held by `data`; may
/// point anywhere in its range.
ptr: *mut S::Elem,
ptr: std::ptr::NonNull<S::Elem>,
/// The lengths of the axes.
dim: D,
/// The element count stride per axis. To be parsed as `isize`.
@@ -1523,7 +1524,7 @@ where
let ptr = self.ptr;
let mut strides = dim.clone();
strides.slice_mut().copy_from_slice(self.strides.slice());
unsafe { ArrayView::new_(ptr, dim, strides) }
unsafe { ArrayView::new_(ptr.as_ptr(), dim, strides) }
}

fn raw_strides(&self) -> D {
42 changes: 21 additions & 21 deletions src/linalg/impl_linalg.rs
Original file line number Diff line number Diff line change
@@ -108,9 +108,9 @@ where
if blas_compat_1d::<$ty, _>(self) && blas_compat_1d::<$ty, _>(rhs) {
unsafe {
let (lhs_ptr, n, incx) =
blas_1d_params(self.ptr, self.len(), self.strides()[0]);
blas_1d_params(self.ptr.as_ptr(), self.len(), self.strides()[0]);
let (rhs_ptr, _, incy) =
blas_1d_params(rhs.ptr, rhs.len(), rhs.strides()[0]);
blas_1d_params(rhs.ptr.as_ptr(), rhs.len(), rhs.strides()[0]);
let ret = blas_sys::$func(
n,
lhs_ptr as *const $ty,
@@ -432,17 +432,17 @@ fn mat_mul_impl<A>(
CblasRowMajor,
lhs_trans,
rhs_trans,
m as blas_index, // m, rows of Op(a)
n as blas_index, // n, cols of Op(b)
k as blas_index, // k, cols of Op(a)
cast_as(&alpha), // alpha
lhs_.ptr as *const _, // a
lhs_stride, // lda
rhs_.ptr as *const _, // b
rhs_stride, // ldb
cast_as(&beta), // beta
c_.ptr as *mut _, // c
c_stride, // ldc
m as blas_index, // m, rows of Op(a)
n as blas_index, // n, cols of Op(b)
k as blas_index, // k, cols of Op(a)
cast_as(&alpha), // alpha
lhs_.ptr.as_ptr() as *const _, // a
lhs_stride, // lda
rhs_.ptr.as_ptr() as *const _, // b
rhs_stride, // ldb
cast_as(&beta), // beta
c_.ptr.as_ptr() as *mut _, // c
c_stride, // ldc
);
}
return;
@@ -630,15 +630,15 @@ pub fn general_mat_vec_mul<A, S1, S2, S3>(
blas_sys::$gemv(
layout,
a_trans,
m as blas_index, // m, rows of Op(a)
k as blas_index, // n, cols of Op(a)
cast_as(&alpha), // alpha
a.ptr as *const _, // a
a_stride, // lda
x.ptr as *const _, // x
m as blas_index, // m, rows of Op(a)
k as blas_index, // n, cols of Op(a)
cast_as(&alpha), // alpha
a.ptr.as_ptr() as *const _, // a
a_stride, // lda
x.ptr.as_ptr() as *const _, // x
x_stride,
cast_as(&beta), // beta
y.ptr as *mut _, // x
cast_as(&beta), // beta
y.ptr.as_ptr() as *mut _, // x
y_stride,
);
}
6 changes: 3 additions & 3 deletions src/zip/mod.rs
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ where
type Output = ArrayView<'a, A, E::Dim>;
fn broadcast_unwrap(self, shape: E) -> Self::Output {
let res: ArrayView<'_, A, E::Dim> = (&self).broadcast_unwrap(shape.into_dimension());
unsafe { ArrayView::new_(res.ptr, res.dim, res.strides) }
unsafe { ArrayView::new_(res.ptr.as_ptr(), res.dim, res.strides) }
}
private_impl! {}
}
@@ -317,7 +317,7 @@ impl<'a, A, D: Dimension> NdProducer for ArrayView<'a, A, D> {

#[doc(hidden)]
unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A {
self.ptr.offset(i.index_unchecked(&self.strides))
self.ptr.as_ptr().offset(i.index_unchecked(&self.strides))
}

#[doc(hidden)]
@@ -370,7 +370,7 @@ impl<'a, A, D: Dimension> NdProducer for ArrayViewMut<'a, A, D> {

#[doc(hidden)]
unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A {
self.ptr.offset(i.index_unchecked(&self.strides))
self.ptr.as_ptr().offset(i.index_unchecked(&self.strides))
}

#[doc(hidden)]