• Brendan Murphy's avatar
    Changes due to new numpy scalar promotion rules · f359c0c4
    Brendan Murphy 提交于
    1. Changed autocaster due to new promotion rules
    
    With "weak promotion" of python types in Numpy 2.0,
    the statement `1.1 == np.asarray(1.1).astype('float32')` is True,
    whereas in Numpy 1.26, it was false.
    
    However, in numpy 1.26, `1.1 == np.asarray([1.1]).astype('float32')`
    was true, so the scalar behavior and array behavior are the same
    in Numpy 2.0, while they were different in numpy 1.26.
    
    Essentially, in Numpy 2.0, if python floats are used in operations
    with numpy floats or arrays, then the type of the numpy object will
    be used (i.e. the python value will be treated as the type of the numpy
    objects).
    
    To preserve the behavior of `NumpyAutocaster` from numpy <= 1.26, I've
    added an explicit conversion of the value to be converted to a numpy
    type using `np.asarray` during the check that decides what dtype to
    cast to.
    
    2. Updates due to new numpy conversion rules for out-of-bounds python
    ints
    
    In numpy 2.0, out of bounds python ints will not be automatically
    converted, and will raise an `OverflowError` instead.
    For instance, converting 255 to int8 will raise an error, instead of
    returning -1.
    
    To explicitly force conversion, we must use
    `np.asarray(value).astype(dtype)`, rather than
    `np.asarray(value, dtype=dtype)`.
    
    The code in `TensorType.filter` has been changed to the new recommended
    way to downcast, and the error type caught by some tests has been
    changed to OverflowError from TypeError
    f359c0c4
名称
最后提交
最后更新
..
function 正在载入提交数据...
__init__.py 正在载入提交数据...
test_builders.py 正在载入提交数据...
test_compilelock.py 正在载入提交数据...
test_debugmode.py 正在载入提交数据...
test_misc.py 正在载入提交数据...
test_mode.py 正在载入提交数据...
test_monitormode.py 正在载入提交数据...
test_nanguardmode.py 正在载入提交数据...
test_ops.py 正在载入提交数据...
test_profiling.py 正在载入提交数据...
test_shared.py 正在载入提交数据...