Add as_ptr and as_mut_ptr methods
This is useful for moving around a matrix/slice in unsafe code and for converting slices to other types (e.g. `ndarray::ArrayView`).
This commit is contained in:
parent
c36416b9c0
commit
267d9760bd
|
@ -274,6 +274,15 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||||
self.data.get_unchecked(irow, icol)
|
self.data.get_unchecked(irow, icol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a pointer to the start of the matrix.
|
||||||
|
///
|
||||||
|
/// If the matrix is not empty, this pointer is guaranteed to be aligned
|
||||||
|
/// and non-null.
|
||||||
|
#[inline]
|
||||||
|
pub fn as_ptr(&self) -> *const N {
|
||||||
|
self.data.ptr()
|
||||||
|
}
|
||||||
|
|
||||||
/// Tests whether `self` and `rhs` are equal up to a given epsilon.
|
/// Tests whether `self` and `rhs` are equal up to a given epsilon.
|
||||||
///
|
///
|
||||||
/// See `relative_eq` from the `RelativeEq` trait for more details.
|
/// See `relative_eq` from the `RelativeEq` trait for more details.
|
||||||
|
@ -550,6 +559,15 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
||||||
MatrixIterMut::new(&mut self.data)
|
MatrixIterMut::new(&mut self.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a mutable pointer to the start of the matrix.
|
||||||
|
///
|
||||||
|
/// If the matrix is not empty, this pointer is guaranteed to be aligned
|
||||||
|
/// and non-null.
|
||||||
|
#[inline]
|
||||||
|
pub fn as_mut_ptr(&mut self) -> *mut N {
|
||||||
|
self.data.ptr_mut()
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets a mutable reference to the i-th element of this matrix.
|
/// Gets a mutable reference to the i-th element of this matrix.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn get_unchecked_mut(&mut self, irow: usize, icol: usize) -> &mut N {
|
pub unsafe fn get_unchecked_mut(&mut self, irow: usize, icol: usize) -> &mut N {
|
||||||
|
|
Loading…
Reference in New Issue