Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Rodney_T_
Beginner
154 Views

ippsMaxIndx_32f bug with -INFINITY

Bug:
Calling ippsMaxIndx_32f on array containing values initialised to -Infinity will sometimes fail.

Detail:
Calling ippsMaxIndx_32f on an array containing values initialised to -Infinity (00 00 80 ff), will set pIndx to len, for length values >33 and where (len % 8) != 0. In these cases the returned IppStatus is set to ippStsNoErr. Attempting to use the returned index on the original array results in seg fault / out of range exception.

Environment:

  • IPP Version 9.0.3
  • Visual Studio 2015
  • x64 Debug build
  • Windows 7 64-bit
  • Intel Core i7-2600

To reproduce:

#include "stdafx.h"
#include <ipp.h>
#include <limits>
#include <iostream>
#include <assert.h>

bool testMaxIndx_32f(int length, float value)
{
	Ipp32f  max = 0.0f;
	int     maxIdx = 0;
	Ipp32f* tmpArray;

	tmpArray = ippsMalloc_32f(length);
	
	for (int i = 0; i < length; ++i)
		tmpArray = value;

	IppStatus status = ippsMaxIndx_32f(tmpArray, length, &max, &maxIdx);
	assert(status == ippStsNoErr);
	
	ippsFree(tmpArray);
	
	return (maxIdx != length);
}

int main()
{
	// Test using IPP alloc
	for (int len = 1; len < 100; ++len)
	{
		if (!testMaxIndx_32f(len, -INFINITY))
			std::cout << "ippsMaxIndx error for -INFINITY and length " << len << " (Ipp Alloc)" << std::endl;
	}
}

Output (trimmed):

ippsMaxIndx error for -INFINITY and length 34 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 35 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 36 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 37 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 38 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 39 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 41 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 42 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 43 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 44 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 45 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 46 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 47 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 49 (Ipp Alloc)
ippsMaxIndx error for -INFINITY and length 50 (Ipp Alloc)

Notes:
The corresponding error exists with ippsMinIndx_32f and positive INFINITY. I have not tested if the same issue occurs with other datatypes (64f/16s/32s).
 

0 Kudos
6 Replies
Zhen_Z_Intel
Employee
154 Views

Hi Rodney,

I could not reproduce your problem in IPP 9.0.3 & VS 2015. On the other hand, the name for variables/const probably could not start from minus sign, only underline and letter. The "INFINITY" is defined in cmath lib, but probably do not have "-INFINITY", I feel confused with the value you described  -Infinity (00 00 80 ff). Largest value of 32bits float is 3.402823 × 1038 , and inf should be bigger than max value, but do not have a specified value.

Best regards,
Fiona

Rodney_T_
Beginner
154 Views

Hi Fiona,

(00 00 80 FF) is the representation of negative infinity as per IEEE-754 (https://en.wikipedia.org/wiki/IEEE_754-1985#Positive_and_negative_infinity). INFINITY is defined in cmath, and -INFINITY is the same as -1.0f*INFINITY, ie it just changes the sign bit of the floating point number.

I'm confused by your response, were you unable to compile my example? Or did your application not fail the test?

If you have an email address I can send you a VS2015 solution. 

Cheers, Rodney

Rodney_T_
Beginner
154 Views

Example solution attached.

 

 

Rodney_T_
Beginner
154 Views

For array lengths 1 through 33 it behaves as I expected from the documentation:
- pMax contains the value '-inf' (00 0 80 FF)
- pIndx contains the value 0, ie the first index from the beginning with equal maximum element

However when the array length reaches 34, and beyond:
- pMax contains the value '-3.40282347e+38' (max float value that is NOT infinity)
- pIndx contains the value 34, ie an out of bounds index (although in some instances it returns an index of 4).
- The returned status is ippStsNoErr

When it reaches array length of 40, and multiples of 8, it again behaves as I expect:

- pMax contains the value '-inf' (00 0 80 FF)
- pIndx contains the value 0, ie the first index from the beginning with equal maximum element

Ivan_Z_Intel
Employee
154 Views

Hi all,

There are the bugs in functions ipps{Min|Max}Indx_{32f|64f}. The functions run incorrectly if all elements of source vector equal Inf (-Inf) and vector length is more 34. For types 16s, 32 these functions run correctly.

This bug will be fixed in the next versions.

Thank you very much for the example of incorrect work of these functions.

Rodney_T_
Beginner
154 Views

Hi Ivan, thanks for your response. I look forward to the fix in the next release.

Reply