@@ -103,7 +103,7 @@ where
103
103
///
104
104
/// This is a replacement of `Index::index` since it forces us a wrong lifetime
105
105
/// https://github.com/bluss/rust-ndarray/issues/371
106
- pub fn elem_ref < I : NdIndex < D > > ( & self , index : I ) -> & ' a A {
106
+ pub fn elem < I : NdIndex < D > > ( & self , index : I ) -> & ' a A {
107
107
debug_bounds_check ! ( self , index) ;
108
108
unsafe {
109
109
& * self . as_ptr ( ) . offset (
@@ -113,17 +113,23 @@ where
113
113
)
114
114
}
115
115
}
116
+
117
+ /// Get a reference of a element through the view without boundary check
118
+ ///
119
+ /// This is a replacement of `Index::index` since it forces us a wrong lifetime
120
+ /// https://github.com/bluss/rust-ndarray/issues/371
121
+ pub fn uelem < I : NdIndex < D > > ( & self , index : I ) -> & ' a A {
122
+ debug_bounds_check ! ( self , index) ;
123
+ unsafe { & * self . as_ptr ( ) . offset ( index. index_unchecked ( & self . strides ) ) }
124
+ }
116
125
}
117
126
118
127
impl < ' a , A , D > ArrayViewMut < ' a , A , D >
119
128
where
120
129
D : Dimension ,
121
130
{
122
- /// Get a mutable reference of a element through the view.
123
- ///
124
- /// This is a replacement of `IndexMut::index_mut` since it forces us a wrong lifetime
125
- /// https://github.com/bluss/rust-ndarray/issues/371
126
- pub fn elem_ref_mut < I : NdIndex < D > > ( & mut self , index : I ) -> & ' a mut A {
131
+ /// Convert a mutable array view to a mutable reference of a element.
132
+ pub fn into_elem < I : NdIndex < D > > ( mut self , index : I ) -> & ' a mut A {
127
133
debug_bounds_check ! ( self , index) ;
128
134
unsafe {
129
135
& mut * self . as_mut_ptr ( ) . offset (
@@ -133,6 +139,16 @@ where
133
139
)
134
140
}
135
141
}
142
+
143
+ /// Convert a mutable array view to a mutable reference of a element without boundary check
144
+ pub fn into_elem_unchecked < I : NdIndex < D > > ( mut self , index : I ) -> & ' a mut A {
145
+ debug_bounds_check ! ( self , index) ;
146
+ unsafe {
147
+ & mut * self . as_mut_ptr ( ) . offset (
148
+ index. index_unchecked ( & self . strides ) ,
149
+ )
150
+ }
151
+ }
136
152
}
137
153
138
154
/// Return `true` if the array shapes and all elements of `self` and
0 commit comments