[arrayfire] 84/248: basic unit tests for `af::cov` and `af_cov`

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:07 UTC 2015


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

ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.

commit d7ce9faa6141e6dbc6b009ae61912395d8ca3925
Author: pradeep <pradeep at arrayfire.com>
Date:   Mon Sep 28 14:06:49 2015 -0400

    basic unit tests for `af::cov` and `af_cov`
---
 test/covariance.cpp | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/data           |   2 +-
 2 files changed, 135 insertions(+), 1 deletion(-)

diff --git a/test/covariance.cpp b/test/covariance.cpp
new file mode 100644
index 0000000..dc5ca09
--- /dev/null
+++ b/test/covariance.cpp
@@ -0,0 +1,134 @@
+/*******************************************************
+ * Copyright (c) 2014, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <gtest/gtest.h>
+#include <arrayfire.h>
+#include <af/dim4.hpp>
+#include <af/traits.hpp>
+#include <string>
+#include <vector>
+#include <ctime>
+#include <iostream>
+#include <algorithm>
+#include <testHelpers.hpp>
+
+using std::string;
+using std::vector;
+using namespace af;
+
+template<typename T>
+class Covariance : public ::testing::Test
+{
+    public:
+        virtual void SetUp() {}
+};
+
+// create a list of types to be tested
+typedef ::testing::Types<float, double, int, uint, intl, uintl, uchar, short, ushort> TestTypes;
+
+// register the type list
+TYPED_TEST_CASE(Covariance, TestTypes);
+
+template<typename T>
+struct f32HelperType {
+   typedef typename cond_type<is_same_type<T, double>::value,
+                                             double,
+                                             float>::type type;
+};
+
+template<typename T>
+struct c32HelperType {
+   typedef typename cond_type<is_same_type<T, cfloat>::value,
+                                             cfloat,
+                                             typename f32HelperType<T>::type >::type type;
+};
+
+template<typename T>
+struct elseType {
+   typedef typename cond_type< is_same_type<T, uintl>::value ||
+                               is_same_type<T, intl> ::value,
+                                              double,
+                                              T>::type type;
+};
+
+template<typename T>
+struct covOutType {
+   typedef typename cond_type< is_same_type<T, float>   ::value ||
+                               is_same_type<T, int>     ::value ||
+                               is_same_type<T, uint>    ::value ||
+                               is_same_type<T, uchar>   ::value ||
+                               is_same_type<T, short>   ::value ||
+                               is_same_type<T, ushort>  ::value ||
+                               is_same_type<T, char>    ::value,
+                                              float,
+                              typename elseType<T>::type>::type type;
+};
+
+template<typename T>
+void covTest(string pFileName, bool isbiased=false)
+{
+    typedef typename covOutType<T>::type outType;
+    if (noDoubleTests<T>()) return;
+    if (noDoubleTests<outType>()) return;
+
+    vector<af::dim4>      numDims;
+    vector<vector<int> >        in;
+    vector<vector<float> >   tests;
+
+    readTestsFromFile<int,float>(pFileName, numDims, in, tests);
+
+    af::dim4 dims1 = numDims[0];
+    af::dim4 dims2 = numDims[1];
+    vector<T> input1(in[0].begin(), in[0].end());
+    vector<T> input2(in[1].begin(), in[1].end());
+
+    array a(dims1, &(input1.front()));
+    array b(dims2, &(input2.front()));
+
+    array c = cov(a, b, isbiased);
+
+    vector<outType> currGoldBar(tests[0].begin(), tests[0].end());
+
+    size_t nElems    = currGoldBar.size();
+    outType *outData = new outType[nElems];
+
+    c.host((void*)outData);
+
+    for (size_t elIter=0; elIter<nElems; ++elIter) {
+        ASSERT_NEAR(::real(currGoldBar[elIter]), ::real(outData[elIter]), 1.0e-3)<< "at: " << elIter<< std::endl;
+        ASSERT_NEAR(::imag(currGoldBar[elIter]), ::imag(outData[elIter]), 1.0e-3)<< "at: " << elIter<< std::endl;
+    }
+
+    // cleanup
+    delete[] outData;
+}
+
+TYPED_TEST(Covariance, Vector)
+{
+    covTest<TypeParam>(string(TEST_DIR "/covariance/vec_size60.test"), false);
+}
+
+TYPED_TEST(Covariance, Matrix)
+{
+    covTest<TypeParam>(string(TEST_DIR "/covariance/matrix_65x121.test"), false);
+}
+
+TEST(Covariance, c32)
+{
+    array a = constant(cfloat(1.0f, -1.0f), 10, c32);
+    array b = constant(cfloat(2.0f, -1.0f), 10, c32);
+    ASSERT_THROW(cov(a, b), af::exception);
+}
+
+TEST(Covariance, c64)
+{
+    array a = constant(cdouble(1.0, -1.0), 10, c64);
+    array b = constant(cdouble(2.0, -1.0), 10, c64);
+    ASSERT_THROW(cov(a, b), af::exception);
+}
diff --git a/test/data b/test/data
index 72af981..1a1419f 160000
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 72af9810b1306a837580ac099d8e53b48a4b43c1
+Subproject commit 1a1419f8ccced11b38738ef07d07baeae409620a

-- 
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