[arrayfire] 162/408: Added error checks non-array parameters of susan API

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:46 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/sid
in repository arrayfire.

commit 1a8892b2571cd6a21f142e4f8fcbab0fb9531164
Author: pradeep <pradeep at arrayfire.com>
Date:   Thu Jul 23 14:45:27 2015 -0400

    Added error checks non-array parameters of susan API
    
    Added corresponding unit tests for invalid arguments as well.
---
 src/api/c/susan.cpp |  7 +++++++
 test/susan.cpp      | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/src/api/c/susan.cpp b/src/api/c/susan.cpp
index 2b042ea..6e5a693 100644
--- a/src/api/c/susan.cpp
+++ b/src/api/c/susan.cpp
@@ -53,6 +53,13 @@ af_err af_susan(af_features* out, const af_array in,
     try {
         ArrayInfo info = getInfo(in);
         af::dim4 dims  = info.dims();
+
+        ARG_ASSERT(1, (dims.ndims()>=2 && dims.ndims()<=3));
+        ARG_ASSERT(3, diff_thr > 0.0f);
+        ARG_ASSERT(4, geom_thr > 0.0f);
+        ARG_ASSERT(5, (feature_ratio > 0.0f && feature_ratio <= 1.0f));
+        ARG_ASSERT(6, (dims[0] >= (dim_t)(2*edge+1) || dims[1] >= (dim_t)(2*edge+1)));
+
         af_dtype type  = info.getType();
         switch(type) {
             case f32: *out = susan<float >(in, radius, diff_thr, geom_thr, feature_ratio, edge); break;
diff --git a/test/susan.cpp b/test/susan.cpp
index 1c558f7..568be00 100644
--- a/test/susan.cpp
+++ b/test/susan.cpp
@@ -123,3 +123,47 @@ void susanTest(string pTestFile, float t, float g)
 
 SUSAN_TEST(square_t32_g10, 32, 10);
 SUSAN_TEST(square_t32_g20, 32, 20);
+
+TEST(Susan, InvalidDims)
+{
+    try {
+        af::array a = af::randu(256);
+        af::features out = af::susan(a);
+        EXPECT_TRUE(false);
+    } catch (af::exception &e) {
+        EXPECT_TRUE(true);
+    }
+}
+
+TEST(Susan, InvalidThreshold)
+{
+    try {
+        af::array a = af::randu(256);
+        af::features out = af::susan(a, 3, -32, 10, 0.05f, 3);
+        EXPECT_TRUE(false);
+    } catch (af::exception &e) {
+        EXPECT_TRUE(true);
+    }
+}
+
+TEST(Susan, InvalidFeatureRatio)
+{
+    try {
+        af::array a = af::randu(256);
+        af::features out = af::susan(a, 3, 32, 10, 1.3f, 3);
+        EXPECT_TRUE(false);
+    } catch (af::exception &e) {
+        EXPECT_TRUE(true);
+    }
+}
+
+TEST(Susan, InvalidEdge)
+{
+    try {
+        af::array a = af::randu(128, 128);
+        af::features out = af::susan(a, 3, 32, 10, 1.3f, 129);
+        EXPECT_TRUE(false);
+    } catch (af::exception &e) {
+        EXPECT_TRUE(true);
+    }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list