Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
Announcements

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

New Contributor I
748 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?

1 Solution
Moderator
708 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);

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-signal-and-data-processing/essential-functions/statistical-functions/countinrange.html

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)

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-signal-and-data-processing/essential-functions/statistical-functions/minmax.html

Warm Regards,

Abhishek

6 Replies
Moderator
709 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);

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-signal-and-data-processing/essential-functions/statistical-functions/countinrange.html

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)

https://software.intel.com/content/www/us/en/develop/documentation/ipp-dev-reference/top/volume-1-signal-and-data-processing/essential-functions/statistical-functions/minmax.html

Warm Regards,

Abhishek

New Contributor I
699 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.

New Contributor I
694 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?

Moderator
630 Views

Hi,

Thanks for the details.

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

Moderator
585 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)

Warm Regards,

Abhishek

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