b45ch1 / algopy

AlgoPy is a Research Prototype for Algorithmic Differentation in Python
79 stars 14 forks source link

BUG: UTPM crashes due to shapes given as float #51

Closed pbrod closed 7 years ago

pbrod commented 7 years ago

numpy no longer accepts shapes given as floats. Thus UTPM crashes due to shapes given as float on line 208: https://github.com/b45ch1/algopy/blob/master/algopy/utpm/utpm.py#L208

I would propose to replace that line with these twolines:

    xsize = numpy.size(x)  # numpy.prod(x_shp)
    yr = UTPM( y.data.reshape((D,P) + (xsize,) + shp))
b45ch1 commented 7 years ago

I cannot reproduce the issue. It seems to me that

x_shp = numpy.shape(x)

always returns a tuple of integers and numpy.prod would also return an integer.

Please provide a self contained example and post your output here. Please also include

print(numpy.__version__)
print(algopy.__version__)

in your script.

pbrod commented 7 years ago

Well not all the time. If x is a scalar then numpy.shape(1) == () and numpy.prod(()) returns a float.

>>> import numpy as np
>>> np.__version__
 '1.12.1'
>>> np.prod(())
1.0

However, if x have a shape different from (), then numpy.prod(x_shp) returns a int and everything is ok.

np.prod((1, 23)) 23 algopy.version '0.5.3'