| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0612fb7 commit 424f759
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -823,6 +823,24 @@ impl<A, D: Dimension> ArrayRef<A, D> | |||
| 823 | 823 | { | |
| 824 | 824 | unsafe { self.get_ptr(index).map(|ptr| &*ptr) } | |
| 825 | 825 | } | |
| 826 | + | ||
| 827 | + /// Return `true` if the index is within the array bounds. | ||
| 828 | + /// | ||
| 829 | + /// ``` | ||
| 830 | + /// use ndarray::arr2; | ||
| 831 | + /// | ||
| 832 | + /// let a = arr2(&[[1., 2.], | ||
| 833 | + /// [3., 4.]]); | ||
| 834 | + /// | ||
| 835 | + /// assert!(a.contains((0, 1))); | ||
| 836 | + /// assert!(!a.contains((2, 0))); | ||
| 837 | + /// assert!(!a.contains((0, 2))); | ||
| 838 | + /// ``` | ||
| 839 | + pub fn contains<I>(&self, index: I) -> bool | ||
| 840 | + where I: NdIndex<D> | ||
| 841 | + { | ||
| 842 | + index.index_checked(self._dim(), self._strides()).is_some() | ||
| 843 | + } | ||
| 826 | 844 | } | |
| 827 | 845 | ||
| 828 | 846 | impl<A, D: Dimension> RawRef<A, D> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments