Repository: arrayfire/arrayfire-rust (language: rust)

Issue:
[BUG] Add MatchType support info for match_template in documentation
arrayfire: 3.8.0;
OS: Windows;
cmd operation: Cargo build;

I'm trying to use a function match_template,  however when I choose matchType ::SHD or matchType ::NCC
the compiler closes with the following error:

thread 'main' panicked at 'Error message: One of the function arguments is incorrect
Last error: In function af_err __cdecl af_match_template(void **,void *const ,void *const ,const af_match_type)
In file src\api\c\match_template.cpp:42
Invalid argument at index 3
Expected: (m_type >= AF_SAD && m_type <= AF_LSSD)
 0# af::array::host in afcuda
 1# af::array::host in afcuda
 2# af::array::host in af






Discussion / hints:
@duducv Sorry about the inconvenience. Not all error metrics are implemented for image comparison. SHD and NCC are one of them. Hence, the message indicates the same. This is the current limitation in upstream.

I am changing the issue title to change the docs to reflect the limitation.

Fix patch:
diff --git a/src/vision/mod.rs b/src/vision/mod.rs
index 6c6840a0..671a2e4c 100644
--- a/src/vision/mod.rs
+++ b/src/vision/mod.rs
@@ -501,6 +501,10 @@ where
     T: HasAfEnum + ImageFilterType,
     T::AbsOutType: HasAfEnum,
 {
+    match mtype {
+        MatchType::NCC | MatchType::ZNCC | MatchType::SHD => HANDLE_ERROR(AfError::ERR_ARG),
+        _ => (), // Do nothing valid matching type
+    };
     unsafe {
         let mut temp: af_array = std::ptr::null_mut();
         let err_val = af_match_template(
@@ -670,3 +674,19 @@ where
         (temp.into(), inliers)
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use crate::randu;
+
+    #[test]
+    #[should_panic]
+    fn check_invalid_matchtype() {
+        crate::core::set_device(0);
+        let a = randu!(f32; 10, 10);
+        let b = randu!(f32; 2, 2);
+        super::match_template(&a, &b, crate::MatchType::NCC);
+        super::match_template(&a, &b, crate::MatchType::ZNCC);
+        super::match_template(&a, &b, crate::MatchType::SHD);
+    }
+}


Test patch: