Fill the given `table` with `nrows` rows of data. Values in the i-th row (where 0 <= i < `row_period`) for a multidimensional field with M elements span from i to i + M-1. For subsequent rows, values repeat cyclically. The same goes for the ``c_extra`` column, but values range fro
(table, shape, nrows)
| 178 | |
| 179 | |
| 180 | def fill_table(table, shape, nrows): |
| 181 | """Fill the given `table` with `nrows` rows of data. |
| 182 | |
| 183 | Values in the i-th row (where 0 <= i < `row_period`) for a |
| 184 | multidimensional field with M elements span from i to i + M-1. For |
| 185 | subsequent rows, values repeat cyclically. |
| 186 | |
| 187 | The same goes for the ``c_extra`` column, but values range from |
| 188 | -`row_period`/2 to +`row_period`/2. |
| 189 | |
| 190 | """ |
| 191 | # Reuse already computed data if possible. |
| 192 | tdata = table_data.get((shape, nrows)) |
| 193 | if tdata is not None: |
| 194 | table.append(tdata) |
| 195 | table.flush() |
| 196 | return |
| 197 | |
| 198 | heavy = common.heavy |
| 199 | size = int(np.prod(shape, dtype=tb.utils.SizeType)) |
| 200 | |
| 201 | row, value = table.row, 0 |
| 202 | for nrow in range(nrows): |
| 203 | data = np.arange(value, value + size).reshape(shape) |
| 204 | for type_, sctype in sctype_from_type.items(): |
| 205 | if not heavy and type_ in heavy_types: |
| 206 | continue # skip heavy type in non-heavy mode |
| 207 | colname = "c_%s" % type_ |
| 208 | ncolname = "c_nested/%s" % colname |
| 209 | if type_ == "bool": |
| 210 | coldata = data > (row_period // 2) |
| 211 | elif type_ == "string": |
| 212 | sdata = [str_format % x for x in range(value, value + size)] |
| 213 | coldata = np.array(sdata, dtype=sctype).reshape(shape) |
| 214 | else: |
| 215 | coldata = np.asarray(data, dtype=sctype) |
| 216 | row[ncolname] = row[colname] = coldata |
| 217 | row["c_extra"] = data - (row_period // 2) |
| 218 | row["c_idxextra"] = data - (row_period // 2) |
| 219 | row.append() |
| 220 | value += 1 |
| 221 | if value == row_period: |
| 222 | value = 0 |
| 223 | table.flush() |
| 224 | |
| 225 | # Make computed data reusable. |
| 226 | tdata = table.read() |
| 227 | table_data[(shape, nrows)] = tdata |
| 228 | |
| 229 | |
| 230 | class SilentlySkipTest(common.unittest.SkipTest): |