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