[arrayfire] 92/284: moved rgb_hsv & identity fns to kernel namespace
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:22 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.
commit cc7d665c6b526a6285e9b75be90bb41f493fac35
Author: pradeep <pradeep at arrayfire.com>
Date: Sat Dec 19 11:21:36 2015 -0500
moved rgb_hsv & identity fns to kernel namespace
---
src/backend/cpu/hsv_rgb.cpp | 104 +-----------------------------
src/backend/cpu/identity.cpp | 19 +-----
src/backend/cpu/kernel/hsv_rgb.hpp | 124 ++++++++++++++++++++++++++++++++++++
src/backend/cpu/kernel/identity.hpp | 37 +++++++++++
4 files changed, 166 insertions(+), 118 deletions(-)
diff --git a/src/backend/cpu/hsv_rgb.cpp b/src/backend/cpu/hsv_rgb.cpp
index d20416f..c0f19db 100644
--- a/src/backend/cpu/hsv_rgb.cpp
+++ b/src/backend/cpu/hsv_rgb.cpp
@@ -11,10 +11,9 @@
#include <Array.hpp>
#include <ArrayInfo.hpp>
#include <hsv_rgb.hpp>
-#include <err_cpu.hpp>
-#include <cmath>
#include <platform.hpp>
#include <async_queue.hpp>
+#include <kernel/hsv_rgb.hpp>
using af::dim4;
@@ -28,56 +27,7 @@ Array<T> hsv2rgb(const Array<T>& in)
Array<T> out = createEmptyArray<T>(in.dims());
- auto func = [=](Array<T> out, const Array<T> in) {
- const dim4 dims = in.dims();
- const dim4 strides = in.strides();
- dim_t obStride = out.strides()[3];
- dim_t coff = strides[2];
- dim_t bCount = dims[3];
-
- for(dim_t b=0; b<bCount; ++b) {
- const T* src = in.get() + b * strides[3];
- T* dst = out.get() + b * obStride;
-
- for(dim_t j=0; j<dims[1]; ++j) {
- dim_t jOff = j*strides[1];
- // j steps along 2nd dimension
- for(dim_t i=0; i<dims[0]; ++i) {
- // i steps along 1st dimension
- dim_t hIdx = i*strides[0] + jOff;
- dim_t sIdx = hIdx + coff;
- dim_t vIdx = sIdx + coff;
-
- T H = src[hIdx];
- T S = src[sIdx];
- T V = src[vIdx];
-
- T R, G, B;
- R = G = B = 0;
-
- int m = (int)(H * 6);
- T f = H * 6 - m;
- T p = V * (1 - S);
- T q = V * (1 - f * S);
- T t = V * (1 - (1 - f) * S);
-
- switch (m % 6) {
- case 0: R = V, G = t, B = p; break;
- case 1: R = q, G = V, B = p; break;
- case 2: R = p, G = V, B = t; break;
- case 3: R = p, G = q, B = V; break;
- case 4: R = t, G = p, B = V; break;
- case 5: R = V, G = p, B = q; break;
- }
-
- dst[hIdx] = R;
- dst[sIdx] = G;
- dst[vIdx] = B;
- }
- }
- }
- };
- getQueue().enqueue(func, out, in);
+ getQueue().enqueue(kernel::hsv2rgb<T>, out, in);
return out;
}
@@ -89,55 +39,7 @@ Array<T> rgb2hsv(const Array<T>& in)
Array<T> out = createEmptyArray<T>(in.dims());
- auto func = [=](Array<T> out, const Array<T> in) {
- const dim4 dims = in.dims();
- const dim4 strides = in.strides();
- dim4 oStrides = out.strides();
- dim_t bCount = dims[3];
-
- for(dim_t b=0; b<bCount; ++b) {
- const T* src = in.get() + b * strides[3];
- T* dst = out.get() + b * oStrides[3];
-
- for(dim_t j=0; j<dims[1]; ++j) {
- // j steps along 2nd dimension
- dim_t oj = j * oStrides[1];
- dim_t ij = j * strides[1];
-
- for(dim_t i=0; i<dims[0]; ++i) {
- // i steps along 1st dimension
- dim_t oIdx0 = i * oStrides[0] + oj;
- dim_t oIdx1 = oIdx0 + oStrides[2];
- dim_t oIdx2 = oIdx1 + oStrides[2];
-
- dim_t iIdx0 = i * strides[0] + ij;
- dim_t iIdx1 = iIdx0 + strides[2];
- dim_t iIdx2 = iIdx1 + strides[2];
-
- T R = src[iIdx0];
- T G = src[iIdx1];
- T B = src[iIdx2];
- T Cmax = std::max(std::max(R, G), B);
- T Cmin = std::min(std::min(R, G), B);
- T delta= Cmax-Cmin;
-
- T H = 0;
-
- if (Cmax!=Cmin) {
- if (Cmax==R) H = (G-B)/delta + (G<B ? 6 : 0);
- if (Cmax==G) H = (B-R)/delta + 2;
- if (Cmax==B) H = (R-G)/delta + 4;
- H = H / 6.0f;
- }
-
- dst[oIdx0] = H;
- dst[oIdx1] = (Cmax==0.0f ? 0 : delta/Cmax);
- dst[oIdx2] = Cmax;
- }
- }
- }
- };
- getQueue().enqueue(func, out, in);
+ getQueue().enqueue(kernel::rgb2hsv<T>, out, in);
return out;
}
diff --git a/src/backend/cpu/identity.cpp b/src/backend/cpu/identity.cpp
index 55c4417..949fced 100644
--- a/src/backend/cpu/identity.cpp
+++ b/src/backend/cpu/identity.cpp
@@ -7,14 +7,12 @@
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
-#include <af/array.h>
#include <af/dim4.hpp>
-#include <af/defines.h>
#include <Array.hpp>
#include <identity.hpp>
-#include <math.hpp>
#include <platform.hpp>
#include <async_queue.hpp>
+#include <kernel/identity.hpp>
namespace cpu
{
@@ -24,20 +22,7 @@ Array<T> identity(const dim4& dims)
{
Array<T> out = createEmptyArray<T>(dims);
- auto func = [=] (Array<T> out) {
- T *ptr = out.get();
- const dim_t *out_dims = out.dims().get();
-
- for (dim_t k = 0; k < out_dims[2] * out_dims[3]; k++) {
- for (dim_t j = 0; j < out_dims[1]; j++) {
- for (dim_t i = 0; i < out_dims[0]; i++) {
- ptr[j * out_dims[0] + i] = (i == j) ? scalar<T>(1) : scalar<T>(0);
- }
- }
- ptr += out_dims[0] * out_dims[1];
- }
- };
- getQueue().enqueue(func, out);
+ getQueue().enqueue(kernel::identity<T>, out);
return out;
}
diff --git a/src/backend/cpu/kernel/hsv_rgb.hpp b/src/backend/cpu/kernel/hsv_rgb.hpp
new file mode 100644
index 0000000..d8aa954
--- /dev/null
+++ b/src/backend/cpu/kernel/hsv_rgb.hpp
@@ -0,0 +1,124 @@
+/*******************************************************
+* Copyright (c) 2015, 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 <cmath>
+
+namespace cpu
+{
+namespace kernel
+{
+
+using af::dim4;
+
+template<typename T>
+void hsv2rgb(Array<T> out, Array<T> const in)
+{
+ const dim4 dims = in.dims();
+ const dim4 strides = in.strides();
+ dim_t obStride = out.strides()[3];
+ dim_t coff = strides[2];
+ dim_t bCount = dims[3];
+
+ for(dim_t b=0; b<bCount; ++b) {
+ const T* src = in.get() + b * strides[3];
+ T* dst = out.get() + b * obStride;
+
+ for(dim_t j=0; j<dims[1]; ++j) {
+ dim_t jOff = j*strides[1];
+ // j steps along 2nd dimension
+ for(dim_t i=0; i<dims[0]; ++i) {
+ // i steps along 1st dimension
+ dim_t hIdx = i*strides[0] + jOff;
+ dim_t sIdx = hIdx + coff;
+ dim_t vIdx = sIdx + coff;
+
+ T H = src[hIdx];
+ T S = src[sIdx];
+ T V = src[vIdx];
+
+ T R, G, B;
+ R = G = B = 0;
+
+ int m = (int)(H * 6);
+ T f = H * 6 - m;
+ T p = V * (1 - S);
+ T q = V * (1 - f * S);
+ T t = V * (1 - (1 - f) * S);
+
+ switch (m % 6) {
+ case 0: R = V, G = t, B = p; break;
+ case 1: R = q, G = V, B = p; break;
+ case 2: R = p, G = V, B = t; break;
+ case 3: R = p, G = q, B = V; break;
+ case 4: R = t, G = p, B = V; break;
+ case 5: R = V, G = p, B = q; break;
+ }
+
+ dst[hIdx] = R;
+ dst[sIdx] = G;
+ dst[vIdx] = B;
+ }
+ }
+ }
+}
+
+template<typename T>
+void rgb2hsv(Array<T> out, Array<T> const in)
+{
+ const dim4 dims = in.dims();
+ const dim4 strides = in.strides();
+ dim4 oStrides = out.strides();
+ dim_t bCount = dims[3];
+
+ for(dim_t b=0; b<bCount; ++b) {
+ const T* src = in.get() + b * strides[3];
+ T* dst = out.get() + b * oStrides[3];
+
+ for(dim_t j=0; j<dims[1]; ++j) {
+ // j steps along 2nd dimension
+ dim_t oj = j * oStrides[1];
+ dim_t ij = j * strides[1];
+
+ for(dim_t i=0; i<dims[0]; ++i) {
+ // i steps along 1st dimension
+ dim_t oIdx0 = i * oStrides[0] + oj;
+ dim_t oIdx1 = oIdx0 + oStrides[2];
+ dim_t oIdx2 = oIdx1 + oStrides[2];
+
+ dim_t iIdx0 = i * strides[0] + ij;
+ dim_t iIdx1 = iIdx0 + strides[2];
+ dim_t iIdx2 = iIdx1 + strides[2];
+
+ T R = src[iIdx0];
+ T G = src[iIdx1];
+ T B = src[iIdx2];
+ T Cmax = std::max(std::max(R, G), B);
+ T Cmin = std::min(std::min(R, G), B);
+ T delta= Cmax-Cmin;
+
+ T H = 0;
+
+ if (Cmax!=Cmin) {
+ if (Cmax==R) H = (G-B)/delta + (G<B ? 6 : 0);
+ if (Cmax==G) H = (B-R)/delta + 2;
+ if (Cmax==B) H = (R-G)/delta + 4;
+ H = H / 6.0f;
+ }
+
+ dst[oIdx0] = H;
+ dst[oIdx1] = (Cmax==0.0f ? 0 : delta/Cmax);
+ dst[oIdx2] = Cmax;
+ }
+ }
+ }
+}
+
+}
+}
diff --git a/src/backend/cpu/kernel/identity.hpp b/src/backend/cpu/kernel/identity.hpp
new file mode 100644
index 0000000..9eab13b
--- /dev/null
+++ b/src/backend/cpu/kernel/identity.hpp
@@ -0,0 +1,37 @@
+/*******************************************************
+ * 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 <math.hpp>
+
+namespace cpu
+{
+namespace kernel
+{
+
+using af::dim4;
+
+template<typename T>
+void identity(Array<T> out)
+{
+ T *ptr = out.get();
+ const dim4 out_dims = out.dims();
+
+ for (dim_t k = 0; k < out_dims[2] * out_dims[3]; k++) {
+ for (dim_t j = 0; j < out_dims[1]; j++) {
+ for (dim_t i = 0; i < out_dims[0]; i++) {
+ ptr[j * out_dims[0] + i] = (i == j) ? scalar<T>(1) : scalar<T>(0);
+ }
+ }
+ ptr += out_dims[0] * out_dims[1];
+ }
+}
+
+}
+}
--
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