#NEWLINE# def test_logsumexp( ) : #NEWLINE# #INDENT# inf = float ( 'inf' ) #NEWLINE# nan = float ( 'nan' ) #NEWLINE# with pytest . raises ( OverflowError ) : #NEWLINE# #INDENT# math . log ( sum ( map ( math . exp , range ( 1000 ) ) ) ) #NEWLINE# #UNINDENT# assert ( relerr ( 999.4586751453871 , logsumexp ( range ( 1000 ) ) ) < 1e-15 ) #NEWLINE# assert ( logsumexp ( [ ] ) == ( - inf ) ) #NEWLINE# assert ( logsumexp ( [ ( - 1000.0 ) ] ) == ( - 1000.0 ) ) #NEWLINE# assert ( logsumexp ( [ ( - 1000.0 ) , ( - 1000.0 ) ] ) == ( ( - 1000.0 ) + math . log ( 2.0 ) ) ) #NEWLINE# assert ( relerr ( math . log ( 2.0 ) , logsumexp ( [ 0.0 , 0.0 ] ) ) < 1e-15 ) #NEWLINE# assert ( logsumexp ( [ ( - inf ) , 1 ] ) == 1 ) #NEWLINE# assert ( logsumexp ( [ ( - inf ) , ( - inf ) ] ) == ( - inf ) ) #NEWLINE# assert ( logsumexp ( [ ( + inf ) , ( + inf ) ] ) == ( + inf ) ) #NEWLINE# assert math . isnan ( logsumexp ( [ ( - inf ) , ( + inf ) ] ) ) #NEWLINE# assert math . isnan ( logsumexp ( [ nan , inf ] ) ) #NEWLINE# assert math . isnan ( logsumexp ( [ nan , ( - 3 ) ] ) )