[arrayfire] 126/408: Add SVD CPU Backend
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:35 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 2969c7331cf095aa190c11375e0f3ff751db776f
Author: Richard Klemm <richy at coding-reality.de>
Date: Sat Jul 4 22:40:06 2015 +0200
Add SVD CPU Backend
---
src/backend/cpu/svd.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
src/backend/cpu/svd.hpp | 20 ++++++++++++
2 files changed, 104 insertions(+)
diff --git a/src/backend/cpu/svd.cpp b/src/backend/cpu/svd.cpp
new file mode 100644
index 0000000..4a1aebf
--- /dev/null
+++ b/src/backend/cpu/svd.cpp
@@ -0,0 +1,84 @@
+/*******************************************************
+ * 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 <Array.hpp>
+#include <svd.hpp>
+#include <err_common.hpp>
+
+#include <err_cpu.hpp>
+
+#define INSTANTIATE_SVD(T) \
+ template void svd<T>(Array<T> & s, Array<T> & u, Array<T> & vt, const Array<T> &in); \
+ template void svdInPlace<T>(Array<T> & s, Array<T> & u, Array<T> & vt, Array<T> &in);
+
+#if defined(WITH_CPU_LINEAR_ALGEBRA)
+#include <lapack_helper.hpp>
+#include <copy.hpp>
+
+namespace cpu
+{
+
+ #define SVD_FUNC_DEF( FUNC ) \
+ template<typename T> FUNC##_func_def<T> FUNC##_func();
+
+ #define SVD_FUNC( FUNC, TYPE, PREFIX ) \
+ template<> FUNC##_func_def<TYPE> FUNC##_func<TYPE>() \
+ { return & LAPACK_NAME(PREFIX##FUNC); }
+
+ template<typename T>
+ using gesdd_func_def = int (*)(ORDER_TYPE, char jobz, int m, int n, T* in,
+ int ldin, T* s, T* u, int ldu,
+ T* vt, int ldvt);
+
+ SVD_FUNC_DEF( gesdd )
+ SVD_FUNC(gesdd, float, s)
+ SVD_FUNC(gesdd, double, d)
+
+ template <typename T>
+ void svdInPlace(Array<T> &s, Array<T> &u, Array<T> &vt, Array<T> &in)
+ {
+ dim4 iDims = in.dims();
+ int M = iDims[0];
+ int N = iDims[1];
+
+ gesdd_func<T>()(AF_LAPACK_COL_MAJOR, 'A', M, N, in.get(), in.strides()[1],
+ s.get(), u.get(), u.strides()[1], vt.get(), vt.strides()[1]);
+ }
+
+ template <typename T>
+ void svd(Array<T> &s, Array<T> &u, Array<T> &vt, const Array<T> &in)
+ {
+ Array<T> in_copy = copyArray<T>(in);
+ svdInPlace(s, u, vt, in_copy);
+ }
+}
+
+#else
+
+namespace cpu
+{
+ template <typename T>
+ void svd(Array<T> &s, Array<T> &u, Array<T> &vt, const Array<T> &in)
+ {
+ AF_ERROR("Linear Algebra is disabled on CPU", AF_ERR_NOT_CONFIGURED);
+ }
+
+ template <typename T>
+ void svdInPlace(Array<T> &s, Array<T> &u, Array<T> &vt, Array<T> &in)
+ {
+ AF_ERROR("Linear Algebra is disabled on CPU", AF_ERR_NOT_CONFIGURED);
+ }
+}
+
+#endif
+
+namespace cpu {
+ INSTANTIATE_SVD(float)
+ INSTANTIATE_SVD(double)
+}
diff --git a/src/backend/cpu/svd.hpp b/src/backend/cpu/svd.hpp
new file mode 100644
index 0000000..d465e8c
--- /dev/null
+++ b/src/backend/cpu/svd.hpp
@@ -0,0 +1,20 @@
+/*******************************************************
+ * 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 <af/util.h>
+#include <Array.hpp>
+
+namespace cpu
+{
+ template <typename T>
+ void svd(Array<T> &s, Array<T> &u, Array<T> &vt, const Array<T> &in);
+
+ template <typename T>
+ void svdInPlace(Array<T> &s, Array<T> &u, Array<T> &vt, Array<T> &in);
+}
--
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