InsertColumn inserts the given tensor as a column to the table at given index, returning an error and not adding if the name is not unique. Automatically adjusts the shape to fit the current number of rows.
(tsr tensor.Tensor, name string, idx int)
| 196 | // returning an error and not adding if the name is not unique. |
| 197 | // Automatically adjusts the shape to fit the current number of rows. |
| 198 | func (dt *Table) InsertColumn(tsr tensor.Tensor, name string, idx int) error { |
| 199 | if _, has := dt.ColumnNameMap[name]; has { |
| 200 | err := fmt.Errorf("table.Table duplicate column name: %s", name) |
| 201 | slog.Warn(err.Error()) |
| 202 | return err |
| 203 | } |
| 204 | dt.ColumnNames = slices.Insert(dt.ColumnNames, idx, name) |
| 205 | dt.UpdateColumnNameMap() |
| 206 | dt.Columns = slices.Insert(dt.Columns, idx, tsr) |
| 207 | rows := max(1, dt.Rows) |
| 208 | tsr.SetNumRows(rows) |
| 209 | return nil |
| 210 | } |
| 211 | |
| 212 | // AddColumnOfType adds a new scalar column to the table, of given reflect type, |
| 213 | // column name (which must be unique), |
no test coverage detected