[arrayfire] 58/75: BUGFIX: Ensure set operations work on vectors only

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:01:18 UTC 2016


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 c38cc2d989fae401daa6cd6a7621f4e6527844b0
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Feb 24 15:16:47 2016 -0500

    BUGFIX: Ensure set operations work on vectors only
---
 src/api/c/set.cpp          | 24 +++++++++++++++++++-----
 src/backend/cuda/set.cu    | 14 +++++++-------
 src/backend/opencl/set.cpp | 14 +++++++-------
 3 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/src/api/c/set.cpp b/src/api/c/set.cpp
index 1643fad..db9b578 100644
--- a/src/api/c/set.cpp
+++ b/src/api/c/set.cpp
@@ -28,7 +28,9 @@ af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted)
 {
     try {
 
-        af_dtype type = getInfo(in).getType();
+        ArrayInfo in_info = getInfo(in);
+        ARG_ASSERT(1, in_info.isVector());
+        af_dtype type = in_info.getType();
 
         af_array res;
         switch(type) {
@@ -62,8 +64,14 @@ af_err af_set_union(af_array *out, const af_array first, const af_array second,
 {
     try {
 
-        af_dtype first_type = getInfo(first).getType();
-        af_dtype second_type = getInfo(second).getType();
+        ArrayInfo first_info = getInfo(first);
+        ArrayInfo second_info = getInfo(second);
+
+        ARG_ASSERT(1, first_info.isVector());
+        ARG_ASSERT(1, second_info.isVector());
+
+        af_dtype first_type = first_info.getType();
+        af_dtype second_type = second_info.getType();
 
         ARG_ASSERT(1, first_type == second_type);
 
@@ -98,8 +106,14 @@ af_err af_set_intersect(af_array *out, const af_array first, const af_array seco
 {
     try {
 
-        af_dtype first_type = getInfo(first).getType();
-        af_dtype second_type = getInfo(second).getType();
+        ArrayInfo first_info = getInfo(first);
+        ArrayInfo second_info = getInfo(second);
+
+        ARG_ASSERT(1, first_info.isVector());
+        ARG_ASSERT(1, second_info.isVector());
+
+        af_dtype first_type = first_info.getType();
+        af_dtype second_type = second_info.getType();
 
         ARG_ASSERT(1, first_type == second_type);
 
diff --git a/src/backend/cuda/set.cu b/src/backend/cuda/set.cu
index 63501d3..4629b8b 100644
--- a/src/backend/cuda/set.cu
+++ b/src/backend/cuda/set.cu
@@ -32,7 +32,7 @@ namespace cuda
         Array<T> out = copyArray<T>(in);
 
         thrust::device_ptr<T> out_ptr = thrust::device_pointer_cast<T>(out.get());
-        thrust::device_ptr<T> out_ptr_end = out_ptr + out.dims()[0];
+        thrust::device_ptr<T> out_ptr_end = out_ptr + out.elements();
 
         if(!is_sorted) THRUST_SELECT(thrust::sort, out_ptr, out_ptr_end);
         thrust::device_ptr<T> out_ptr_last;
@@ -55,14 +55,14 @@ namespace cuda
             unique_second = setUnique(second, false);
         }
 
-        dim_t out_size = unique_first.dims()[0] + unique_second.dims()[0];
+        dim_t out_size = unique_first.elements() + unique_second.elements();
         Array<T> out = createEmptyArray<T>(dim4(out_size));
 
         thrust::device_ptr<T> first_ptr = thrust::device_pointer_cast<T>(unique_first.get());
-        thrust::device_ptr<T> first_ptr_end = first_ptr + unique_first.dims()[0];
+        thrust::device_ptr<T> first_ptr_end = first_ptr + unique_first.elements();
 
         thrust::device_ptr<T> second_ptr = thrust::device_pointer_cast<T>(unique_second.get());
-        thrust::device_ptr<T> second_ptr_end = second_ptr + unique_second.dims()[0];
+        thrust::device_ptr<T> second_ptr_end = second_ptr + unique_second.elements();
 
         thrust::device_ptr<T> out_ptr = thrust::device_pointer_cast<T>(out.get());
 
@@ -87,14 +87,14 @@ namespace cuda
             unique_second = setUnique(second, false);
         }
 
-        dim_t out_size = std::max(unique_first.dims()[0], unique_second.dims()[0]);
+        dim_t out_size = std::max(unique_first.elements(), unique_second.elements());
         Array<T> out = createEmptyArray<T>(dim4(out_size));
 
         thrust::device_ptr<T> first_ptr = thrust::device_pointer_cast<T>(unique_first.get());
-        thrust::device_ptr<T> first_ptr_end = first_ptr + unique_first.dims()[0];
+        thrust::device_ptr<T> first_ptr_end = first_ptr + unique_first.elements();
 
         thrust::device_ptr<T> second_ptr = thrust::device_pointer_cast<T>(unique_second.get());
-        thrust::device_ptr<T> second_ptr_end = second_ptr + unique_second.dims()[0];
+        thrust::device_ptr<T> second_ptr_end = second_ptr + unique_second.elements();
 
         thrust::device_ptr<T> out_ptr = thrust::device_pointer_cast<T>(out.get());
 
diff --git a/src/backend/opencl/set.cpp b/src/backend/opencl/set.cpp
index 5604ff4..c37b7c4 100644
--- a/src/backend/opencl/set.cpp
+++ b/src/backend/opencl/set.cpp
@@ -53,7 +53,7 @@ namespace opencl
             compute::buffer out_data((*out.get())());
 
             compute::buffer_iterator< type_t<T> > begin(out_data, 0);
-            compute::buffer_iterator< type_t<T> > end(out_data, out.dims()[0]);
+            compute::buffer_iterator< type_t<T> > end(out_data, out.elements());
 
             if (!is_sorted) {
                 compute::sort(begin, end, queue);
@@ -83,7 +83,7 @@ namespace opencl
                 unique_second = setUnique(second, false);
             }
 
-            size_t out_size = unique_first.dims()[0] + unique_second.dims()[0];
+            size_t out_size = unique_first.elements() + unique_second.elements();
             Array<T> out = createEmptyArray<T>(dim4(out_size, 1, 1, 1));
 
             compute::command_queue queue(getQueue()());
@@ -93,9 +93,9 @@ namespace opencl
             compute::buffer out_data((*out.get())());
 
             compute::buffer_iterator< type_t<T> > first_begin(first_data, 0);
-            compute::buffer_iterator< type_t<T> > first_end(first_data, unique_first.dims()[0]);
+            compute::buffer_iterator< type_t<T> > first_end(first_data, unique_first.elements());
             compute::buffer_iterator< type_t<T> > second_begin(second_data, 0);
-            compute::buffer_iterator< type_t<T> > second_end(second_data, unique_second.dims()[0]);
+            compute::buffer_iterator< type_t<T> > second_end(second_data, unique_second.elements());
             compute::buffer_iterator< type_t<T> > out_begin(out_data, 0);
 
             compute::buffer_iterator< type_t<T> > out_end = compute::set_union(
@@ -124,7 +124,7 @@ namespace opencl
                 unique_second = setUnique(second, false);
             }
 
-            size_t out_size = std::max(unique_first.dims()[0], unique_second.dims()[0]);
+            size_t out_size = std::max(unique_first.elements(), unique_second.elements());
             Array<T> out = createEmptyArray<T>(dim4(out_size, 1, 1, 1));
 
             compute::command_queue queue(getQueue()());
@@ -134,9 +134,9 @@ namespace opencl
             compute::buffer out_data((*out.get())());
 
             compute::buffer_iterator< type_t<T> > first_begin(first_data, 0);
-            compute::buffer_iterator< type_t<T> > first_end(first_data, unique_first.dims()[0]);
+            compute::buffer_iterator< type_t<T> > first_end(first_data, unique_first.elements());
             compute::buffer_iterator< type_t<T> > second_begin(second_data, 0);
-            compute::buffer_iterator< type_t<T> > second_end(second_data, unique_second.dims()[0]);
+            compute::buffer_iterator< type_t<T> > second_end(second_data, unique_second.elements());
             compute::buffer_iterator< type_t<T> > out_begin(out_data, 0);
 
             compute::buffer_iterator< type_t<T> > out_end = compute::set_intersection(

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