| ... | @@ -86,16 +86,18 @@ pub fn VectorCount(comptime VectorType: type) type { | ... | @@ -86,16 +86,18 @@ pub fn VectorCount(comptime VectorType: type) type { |
| 86 | | 86 | |
| 87 | /// Returns a vector containing the first `len` integers in order from 0 to `len`-1. | 87 | /// Returns a vector containing the first `len` integers in order from 0 to `len`-1. |
| 88 | /// For example, `iota(i32, 8)` will return a vector containing `.{0, 1, 2, 3, 4, 5, 6, 7}`. | 88 | /// For example, `iota(i32, 8)` will return a vector containing `.{0, 1, 2, 3, 4, 5, 6, 7}`. |
| 89 | pub fn iota(comptime T: type, comptime len: usize) @Vector(len, T) { | 89 | pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) { |
| 90 | var out: [len]T = undefined; | 90 | comptime { |
| 91 | for (out) |*element, i| { | 91 | var out: [len]T = undefined; |
| 92 | element.* = switch (@typeInfo(T)) { | 92 | for (out) |*element, i| { |
| 93 | .Int => @intCast(T, i), | 93 | element.* = switch (@typeInfo(T)) { |
| 94 | .Float => @intToFloat(T, i), | 94 | .Int => @intCast(T, i), |
| 95 | else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."), | 95 | .Float => @intToFloat(T, i), |
| 96 | }; | 96 | else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."), |
| | 97 | }; |
| | 98 | } |
| | 99 | return @as(@Vector(len, T), out); |
| 97 | } | 100 | } |
| 98 | return @as(@Vector(len, T), out); | | |
| 99 | } | 101 | } |
| 100 | | 102 | |
| 101 | /// Returns a vector containing the same elements as the input, but repeated until the desired length is reached. | 103 | /// Returns a vector containing the same elements as the input, but repeated until the desired length is reached. |