Intel® Integrated Performance Primitives
Community support and discussions relating to developing high-performance vision, signal, security, and storage applications.

Ipp equivalent to any(), all() in python

JohnZhang
Novice
574 Views

I just want to know if an array has any zero value or all zero values? I wonder what is the most efficient way to do this in Ipp or MKL?

0 Kudos
1 Solution
AbhishekD_Intel
Moderator
534 Views

Hi John,


Thanks for reaching out to us.

We don't think there is a completely exact replacement of any() and all() (Python Functions) in IPP.

But there are some functions available in IPP that will help to achieve the same task as that of any() and all().

You may use the CountInRange function that has the capability to count the number of elements lying in between the upper and lower bounds. According to your use-case, you can keep lower bound = -1 and upper bound = 1 which will give the count of 0s in your array. You can also change the lower and upper bound to get the required results.

The Function call will be:

IppStatus ippsCountInRange_32s(const Ipp32s* pSrc, int len, int* pCounts, Ipp32s lowerBound, Ipp32s upperBound);


Please refer to the link below to get more details

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-si...


You may also try using the MinMax function which will give the minimum value and maximum value among the array of elements.

  1. If both min and max values are 0, then all elements of the array are 0(can relate to all() function)
  2. If the only min is 0, then there is at least one element which is 0(can relate to any() function)


Please refer to the below link for more details.

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-si...


Hope this will help you to solve your issue.



Warm Regards,

Abhishek


View solution in original post

6 Replies
AbhishekD_Intel
Moderator
535 Views

Hi John,


Thanks for reaching out to us.

We don't think there is a completely exact replacement of any() and all() (Python Functions) in IPP.

But there are some functions available in IPP that will help to achieve the same task as that of any() and all().

You may use the CountInRange function that has the capability to count the number of elements lying in between the upper and lower bounds. According to your use-case, you can keep lower bound = -1 and upper bound = 1 which will give the count of 0s in your array. You can also change the lower and upper bound to get the required results.

The Function call will be:

IppStatus ippsCountInRange_32s(const Ipp32s* pSrc, int len, int* pCounts, Ipp32s lowerBound, Ipp32s upperBound);


Please refer to the link below to get more details

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-si...


You may also try using the MinMax function which will give the minimum value and maximum value among the array of elements.

  1. If both min and max values are 0, then all elements of the array are 0(can relate to all() function)
  2. If the only min is 0, then there is at least one element which is 0(can relate to any() function)


Please refer to the below link for more details.

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-si...


Hope this will help you to solve your issue.



Warm Regards,

Abhishek


JohnZhang
Novice
525 Views

That is very helpful. Thank you so much. CountRange seems to be the least costy way to do this in Ipp. I was a bit surprised that Ipp does not support this simple logical operation. 

JohnZhang
Novice
520 Views

For a follow-on note, I was searching for a suitable function to avoid divide-by-zero before I call the divide function. Otherwise the divide function will throw a divide-by-zero warning. Is there a clever way to avoid this happening?

AbhishekD_Intel
Moderator
456 Views

Hi,

 

Thanks for the details.

We are looking into it we will get back to you with the updates.

 

 

AbhishekD_Intel
Moderator
411 Views

Hi John,


Apology for the delay.

The thing is that IPP is mainly focused more on optimizing function performance rather than doing these checks on data elements, but you can put some checks while performing these kinds of operations, and IPP's error reporting mechanism will help you to act accordingly.


For your use-case, you may also try checking the status code(IppStatus) returned my IPP functions and this way you can control the application to perform error-related actions.

The status code of divide by zero is ippStsDivisorErr for more details related to other status codes please follow the below link.

Error Reporting (intel.com)


Hope the provided details will help you to solve your issue. Please gives us confirmation if your issue is resolved.



Warm Regards,

Abhishek


AbhishekD_Intel
Moderator
383 Views

Hi,


As we haven't heard back from you, and as your issue has been resolved we will no longer monitor this thread. If you require any additional assistance from Intel, please start a new thread. 

Any further interaction in this thread will be considered community only.


Warm Regards,

Abhishek



Reply