Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: range accepts float #4988

Open
2 tasks done
stuartarchibald opened this issue Dec 19, 2019 · 1 comment
Open
2 tasks done

bug: range accepts float #4988

stuartarchibald opened this issue Dec 19, 2019 · 1 comment
Labels

Comments

@stuartarchibald
Copy link
Contributor

Reporting a bug

This shouldn't make it through typing but it does

from numba import njit
import numpy as np

@njit
def foo(x):
    for i in range(x):
        print(i)

foo(12.3)

range() should not accept a floating point value. This types as:

----------------------------------IR DUMP: foo----------------------------------
label 0:
    x = arg(0, name=x)                       ['x']
    jump 2                                   []
label 2:
    $4load_global.0 = global(range: <class 'range'>) ['$4load_global.0']
    $8call_function.2 = call $4load_global.0(x, func=$4load_global.0, args=[Var(x, range_issue.py:6)], kws=(), vararg=None) ['$4load_global.0', '$8call_function.2', 'x']
    del x                                    []
    del $4load_global.0                      []
    $10get_iter.3 = getiter(value=$8call_function.2) ['$10get_iter.3', '$8call_function.2']
    del $8call_function.2                    []
    $phi12.0 = $10get_iter.3                 ['$10get_iter.3', '$phi12.0']
    del $10get_iter.3                        []
    jump 12                                  []
label 12:
    $12for_iter.1 = iternext(value=$phi12.0) ['$12for_iter.1', '$phi12.0']
    $12for_iter.2 = pair_first(value=$12for_iter.1) ['$12for_iter.1', '$12for_iter.2']
    $12for_iter.3 = pair_second(value=$12for_iter.1) ['$12for_iter.1', '$12for_iter.3']
    del $12for_iter.1                        []
    $phi14.1 = $12for_iter.2                 ['$12for_iter.2', '$phi14.1']
    del $12for_iter.2                        []
    branch $12for_iter.3, 14, 26             ['$12for_iter.3']
label 14:
    del $12for_iter.3                        []
    i = $phi14.1                             ['$phi14.1', 'i']
    del $phi14.1                             []
    $16load_global.2 = global(print: <built-in function print>) ['$16load_global.2']
    del $16load_global.2                     []
    print(i)                                 ['i']
    del i                                    []
    $20call_function.4 = const(NoneType, None) ['$20call_function.4']
    del $20call_function.4                   []
    jump 12                                  []
label 26:
    del $phi14.1                             []
    del $phi12.0                             []
    del $12for_iter.3                        []
    jump 28                                  []
label 28:
    $const28.0 = const(NoneType, None)       ['$const28.0']
    $30return_value.1 = cast(value=$const28.0) ['$30return_value.1', '$const28.0']
    del $const28.0                           []
    return $30return_value.1                 ['$30return_value.1']

-----------------------------------propagate------------------------------------
---- type variables ----
[$10get_iter.3 := range_iter_int32,
 $12for_iter.1 := pair<int32, bool>,
 $12for_iter.2 := int32,
 $12for_iter.3 := bool,
 $16load_global.2 := Function(<built-in function print>),
 $20call_function.4 := none,
 $30return_value.1 := none,
 $4load_global.0 := Function(<class 'range'>),
 $8call_function.2 := range_state_int32,
 $const28.0 := none,
 $phi12.0 := range_iter_int32,
 $phi14.1 := int32,
 arg.x := float64,
 i := int32,
 x := float64]
-----------------------------------propagate------------------------------------
---- type variables ----
[$10get_iter.3 := range_iter_int32,
 $12for_iter.1 := pair<int32, bool>,
 $12for_iter.2 := int32,
 $12for_iter.3 := bool,
 $16load_global.2 := Function(<built-in function print>),
 $20call_function.4 := none,
 $30return_value.1 := none,
 $4load_global.0 := Function(<class 'range'>),
 $8call_function.2 := range_state_int32,
 $const28.0 := none,
 $phi12.0 := range_iter_int32,
 $phi14.1 := int32,
 arg.x := float64,
 i := int32,
 x := float64]
---------------------------------Variable types---------------------------------
{'$10get_iter.3': range_iter_int32,
 '$12for_iter.1': pair<int32, bool>,
 '$12for_iter.2': int32,
 '$12for_iter.3': bool,
 '$16load_global.2': Function(<built-in function print>),
 '$20call_function.4': none,
 '$30return_value.1': none,
 '$4load_global.0': Function(<class 'range'>),
 '$8call_function.2': range_state_int32,
 '$const28.0': none,
 '$phi12.0': range_iter_int32,
 '$phi14.1': int32,
 'arg.x': float64,
 'i': int32,
 'x': float64}
----------------------------------Return type-----------------------------------
none
-----------------------------------Call types-----------------------------------
{call $4load_global.0(x, func=$4load_global.0, args=[Var(x, range_issue.py:6)], kws=(), vararg=None): (int32,) -> range_state_int32,
 getiter(value=$8call_function.2): (range_state_int32,) -> range_iter_int32,
 iternext(value=$phi12.0): (range_iter_int32,) -> pair<int32, bool>,
 <numba.ir.Print object at 0x7fb8630b1810>: (int32,) -> none}
@sklam
Copy link
Member

sklam commented Dec 19, 2019

Likely because of implicit cast from float to int

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants