Skip to content

Commit 71c8c8f

Browse files
jturner314bluss
authored andcommitted
Implement NdProducer for RawArrayView/Mut
1 parent 49948c2 commit 71c8c8f

File tree

1 file changed

+116
-2
lines changed

1 file changed

+116
-2
lines changed

src/zip/mod.rs

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ where
4747

4848
impl<S, D> ArrayBase<S, D>
4949
where
50-
S: Data,
50+
S: RawData,
5151
D: Dimension,
5252
{
5353
pub(crate) fn layout_impl(&self) -> Layout {
@@ -57,7 +57,7 @@ where
5757
} else {
5858
CORDER
5959
}
60-
} else if self.ndim() > 1 && self.t().is_standard_layout() {
60+
} else if self.ndim() > 1 && self.raw_view().reversed_axes().is_standard_layout() {
6161
FORDER
6262
} else {
6363
0
@@ -192,6 +192,14 @@ pub trait Offset: Copy {
192192
private_decl! {}
193193
}
194194

195+
impl<T> Offset for *const T {
196+
type Stride = isize;
197+
unsafe fn stride_offset(self, s: Self::Stride, index: usize) -> Self {
198+
self.offset(s * (index as isize))
199+
}
200+
private_impl! {}
201+
}
202+
195203
impl<T> Offset for *mut T {
196204
type Stride = isize;
197205
unsafe fn stride_offset(self, s: Self::Stride, index: usize) -> Self {
@@ -389,6 +397,112 @@ impl<'a, A, D: Dimension> NdProducer for ArrayViewMut<'a, A, D> {
389397
}
390398
}
391399

400+
impl<A, D: Dimension> NdProducer for RawArrayView<A, D> {
401+
type Item = *const A;
402+
type Dim = D;
403+
type Ptr = *const A;
404+
type Stride = isize;
405+
406+
private_impl! {}
407+
#[doc(hidden)]
408+
fn raw_dim(&self) -> Self::Dim {
409+
self.raw_dim()
410+
}
411+
412+
#[doc(hidden)]
413+
fn equal_dim(&self, dim: &Self::Dim) -> bool {
414+
self.dim.equal(dim)
415+
}
416+
417+
#[doc(hidden)]
418+
fn as_ptr(&self) -> *const A {
419+
self.as_ptr()
420+
}
421+
422+
#[doc(hidden)]
423+
fn layout(&self) -> Layout {
424+
self.layout_impl()
425+
}
426+
427+
#[doc(hidden)]
428+
unsafe fn as_ref(&self, ptr: *const A) -> *const A {
429+
ptr
430+
}
431+
432+
#[doc(hidden)]
433+
unsafe fn uget_ptr(&self, i: &Self::Dim) -> *const A {
434+
self.ptr.as_ptr().offset(i.index_unchecked(&self.strides))
435+
}
436+
437+
#[doc(hidden)]
438+
fn stride_of(&self, axis: Axis) -> isize {
439+
self.stride_of(axis)
440+
}
441+
442+
#[inline(always)]
443+
fn contiguous_stride(&self) -> Self::Stride {
444+
1
445+
}
446+
447+
#[doc(hidden)]
448+
fn split_at(self, axis: Axis, index: usize) -> (Self, Self) {
449+
self.split_at(axis, index)
450+
}
451+
}
452+
453+
impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
454+
type Item = *mut A;
455+
type Dim = D;
456+
type Ptr = *mut A;
457+
type Stride = isize;
458+
459+
private_impl! {}
460+
#[doc(hidden)]
461+
fn raw_dim(&self) -> Self::Dim {
462+
self.raw_dim()
463+
}
464+
465+
#[doc(hidden)]
466+
fn equal_dim(&self, dim: &Self::Dim) -> bool {
467+
self.dim.equal(dim)
468+
}
469+
470+
#[doc(hidden)]
471+
fn as_ptr(&self) -> *mut A {
472+
self.as_ptr() as _
473+
}
474+
475+
#[doc(hidden)]
476+
fn layout(&self) -> Layout {
477+
self.layout_impl()
478+
}
479+
480+
#[doc(hidden)]
481+
unsafe fn as_ref(&self, ptr: *mut A) -> *mut A {
482+
ptr
483+
}
484+
485+
#[doc(hidden)]
486+
unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A {
487+
self.ptr.as_ptr().offset(i.index_unchecked(&self.strides))
488+
}
489+
490+
#[doc(hidden)]
491+
fn stride_of(&self, axis: Axis) -> isize {
492+
self.stride_of(axis)
493+
}
494+
495+
#[inline(always)]
496+
fn contiguous_stride(&self) -> Self::Stride {
497+
1
498+
}
499+
500+
#[doc(hidden)]
501+
fn split_at(self, axis: Axis, index: usize) -> (Self, Self) {
502+
self.split_at(axis, index)
503+
}
504+
}
505+
392506
/// Lock step function application across several arrays or other producers.
393507
///
394508
/// Zip allows matching several producers to each other elementwise and applying

0 commit comments

Comments
 (0)