File tree 2 files changed +6
-1
lines changed
2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ Enhancements
52
52
2D variable.
53
53
By `Deepak Cherian <https://github.com/dcherian >`_.
54
54
- Reduce memory usage when decoding a variable with a scale_factor, by
55
- converting 8-bit and 16-bit integers to float32 instead of float64 (:pull: `1840 `).
55
+ converting 8-bit and 16-bit integers to float32 instead of float64
56
+ (:pull: `1840 `), and keeping float16 and float32 as float32 (:issue: `1842 `).
56
57
By `Zac Hatfield-Dodds <https://github.com/Zac-HD >`_.
57
58
58
59
.. _Zarr : http://zarr.readthedocs.io/
Original file line number Diff line number Diff line change @@ -215,6 +215,10 @@ class CFScaleOffsetCoder(VariableCoder):
215
215
@staticmethod
216
216
def _choose_float_dtype (data , has_offset ):
217
217
"""Return a float dtype sufficient to losslessly represent `data`."""
218
+ # Keep float32 as-is. Upcast half-precision to single-precision,
219
+ # because float16 is "intended for storage but not computation"
220
+ if data .dtype .itemsize <= 4 and np .issubdtype (data .dtype , np .floating ):
221
+ return np .float32
218
222
# float32 can exactly represent all integers up to 24 bits
219
223
if data .dtype .itemsize <= 2 and np .issubdtype (data .dtype , np .integer ):
220
224
# A scale factor is entirely safe (vanishing into the mantissa),
You can’t perform that action at this time.
0 commit comments