|
1 | 1 | Type Promotion
|
2 | 2 | ==============
|
3 | 3 |
|
4 |
| -For operations that involve two input arguments (or more), ``kernel_float`` will first convert the inputs into a common type before applying the operation. |
5 |
| -For example, when adding ``vec<int, N>`` to a ``vec<float, N>``, both arguments must first be converted into a ``vec<float, N>``. |
| 4 | +For operations that involve two (or more) input arguments, ``kernel_float`` will first convert the inputs into a common type before applying the operation. |
| 5 | +For example, when adding ``vec<int, N>`` to ``vec<float, N>``, both arguments must first be converted into a ``vec<float, N>``. |
6 | 6 |
|
7 | 7 | This procedure is called "type promotion" and is implemented as follows.
|
8 |
| -First, all arguments are converted into a vector by calling ``into_vec``. |
9 |
| -Next, all arguments must have length ``N`` or length ``1`` and vectors of length ``1`` are resized to become length ``N``. |
10 |
| -Finally, the vector element types are promoted into a common type. |
| 8 | +Initially, every argument is transformed into a vector using the ``into_vec`` function |
| 9 | +Next, all arguments must have length ``N`` or length ``1``, where vectors of length ``1`` are repeated to become length ``N``. |
| 10 | +Finally, the vector element types are promoted into a shared type. |
11 | 11 |
|
12 | 12 | The rules for element type promotion in ``kernel_float`` are slightly different than in regular C++.
|
13 |
| -In short, for two element types ``T`` and ``U``, the promotion rules can be summarized as follows: |
| 13 | +In a nutshell, for two element types, the promotion rules can be summarized as follows: |
14 | 14 |
|
15 | 15 | * If one of the types is ``bool``, the result is the other type.
|
16 |
| -* If one type is a floating-point type and the other is a signed or unsigned integer, the result is the floating-point type. |
17 |
| -* If both types are floating-point types, the result is the largest of the two types. An exception here is combining ``half`` and ``bfloat16``, which results in ``float``. |
18 |
| -* If both types are integer types of the same signedness, the result is the largest of the two types. |
| 16 | +* If one type is a floating-point and the other is an integer (signed or unsigned), the outcome is the floating-point type. |
| 17 | +* If both are floating-point types, the largest of the two is chosen. An exception is combining ``half`` and ``bfloat16``, which results in ``float``. |
| 18 | +* If both types are integer types of the same signedness, the largest of the two is chosen. |
19 | 19 | * Combining a signed integer and unsigned integer type is not allowed.
|
20 | 20 |
|
21 | 21 | Overview
|
|
0 commit comments