Python 3 integer division results in floats - throws indexing errors in numpy 1.12
Known affected files:
./lib/wavelength_smooth_lib.py
, ./lib/spatial_smooth_lib.py
, ./tools/median-filter-cube.py
Likely results in crash if numpy >= 1.12 and python 3!
Comments (9)
-
repo owner -
repo owner Ah OK - as of numpy 1.12 float indexing is not allowed anymore.
I will change this asap.
-
repo owner - changed status to resolved
Fix for multiprocess slicing (python 3 float division) - fix
#20Since division in python 3 results in a float, the routines that slice the cube over several processors in
spatial_smooth_lib.py
andwavelength_smooth_lib.py
create floats as indexes. From numpy >= 1.12 arrays do not chew float indeces.→ <<cset c5b9cc5d85ac>>
-
reporter Please also change in tools - median-filter-cube.py and any other places this may appear. Thanks for solving this quickly.
-
repo owner Fix for multiprocess slicing (python 3 float division) - fix
#20Since division in python 3 results in a float, the routines that slice the cube over several processors in
spatial_smooth_lib.py
andwavelength_smooth_lib.py
create floats as indexes. From numpy >= 1.12 arrays do not chew float indeces.→ <<cset 3b43087b5105>>
-
repo owner Now also
median_filter_cube.py
is changed. -
repo owner - changed status to open
I reopen this and keep it open as long as I don't merge this into the main branch.... The latter I will do when we are sure everything is working.
-
repo owner - edited description
- changed title to Python 3 integer division results in floats - throws indexing errors in numpy 1.12
-
repo owner - changed status to resolved
fixed in master branch in 3faee80
- Log in to comment
Ah - I see. The affected lines I can think of are in wavelength_smooth_lib.py and spatial_smooth_lib.py
I.e.
for j in range(num_threads): start = j * (length / num_threads) end = (j + 1) * (length / num_threads) endstr = str(end) if j+1 == num_threads: # the last worker has to do some more work if # mod(spaxels,num_threads) != 0 end=length+1 endstr=str(length) if nans_select != None: spectra_part = data[:,~nans_select][:,start:end] else: spectra_part = data[:,start:end]
for wavelength_smooth_lib.py, and
` for j in range(num_threads): part_fac = length/num_threads start = jpart_fac end = (j+1)part_fac if j+1 == num_threads: end = length+1 # so also the last layer gets convolved! print(str(filename)+': Thread '+str(j+1)+\ ': Working on wavelength layers from #'+str(start+1)+\ ' to #'+str(end))
`
for spatial_smooth_lib.py
From just looking at those, and knowing that numpy does not crash on float indexing, but dooing basically int() internally, I think this might be only a cosmetic bug.
Or do I miss something?