Host scalars
int, float and bool are host scalars: Python numbers and booleans, kept on the host rather than on the device, for counters, epochs, seeds and flags. A number written in the source is an int or a float, true and false are bools, and a dim or axis name used as a value is an int. A type that is only int, float or bool declares one, as in steps: int or -> bool. Internally a host scalar is a value of shape [] with a host dtype, and messages show it as int, float or bool.
- Arithmetic on host scalars gives a host scalar:
intwithintgives anint, except that/gives afloat, and anything with afloatgives afloat. Arithmetic with a tensor gives a tensor, with the dtype promotion gives. - A comparison of host scalars gives a
bool, andand,orand!take and givebools; they compile to Python’sand,orandnot. Aboolisn’t a number, so arithmetic on one is E0505, and!,andororon anintis E0501. - A parameter or return type that is a host scalar takes a host scalar or a Python value. An
intfits where afloatis expected, and nothing else converts: afloatwhere anintis expected is E0502, and a tensor, even one of shape[], is E0805, since reading it would wait for the device. x as int,x as floatandx as boolgive a Python value a host type, with a run-time check that it is one (Runtime checks); aboolis neither anintnor afloat. On a tensor, such anasis E0805.to intis E0504: no conversion makes a host scalar of a tensor.- An
intorfloathas a range, as a tensor does (Range inference), so a counter that starts at 0 and is only increased in a loop is in $[0, \infty)$ (Blocks and scope).
A host scalar parameter isn’t checked at run time.