Create vec with items initialized to the given value.
(
builder: LowLevelIRBuilder,
vtype: RVec,
length: int | Value,
init: Value,
line: int,
*,
capacity: Value | None = None,
)
| 144 | |
| 145 | |
| 146 | def vec_create_initialized( |
| 147 | builder: LowLevelIRBuilder, |
| 148 | vtype: RVec, |
| 149 | length: int | Value, |
| 150 | init: Value, |
| 151 | line: int, |
| 152 | *, |
| 153 | capacity: Value | None = None, |
| 154 | ) -> Value: |
| 155 | """Create vec with items initialized to the given value.""" |
| 156 | if isinstance(length, int): |
| 157 | length = Integer(length, c_pyssize_t_rprimitive) |
| 158 | length = as_platform_int(builder, length, line) |
| 159 | |
| 160 | item_type = vtype.item_type |
| 161 | init = builder.coerce(init, item_type, line) |
| 162 | vec = vec_create(builder, vtype, length, line, capacity=capacity) |
| 163 | |
| 164 | items_start = vec_items(builder, vec) |
| 165 | step = step_size(item_type) |
| 166 | items_end = builder.int_add(items_start, builder.int_mul(length, step)) |
| 167 | |
| 168 | for_loop = builder.begin_for( |
| 169 | items_start, items_end, Integer(step, c_pyssize_t_rprimitive), signed=False |
| 170 | ) |
| 171 | vec_set_mem_item(builder, for_loop.index, item_type, init) |
| 172 | for_loop.finish() |
| 173 | |
| 174 | builder.keep_alive([vec], line) |
| 175 | return vec |
| 176 | |
| 177 | |
| 178 | def vec_create_from_values( |
no test coverage detected
searching dependent graphs…