Documentation
¶
Index ¶
- Constants
- Variables
- func AddColumn[T tensor.DataTypes](dt *Table, name string, cellSizes ...int) tensor.Tensor
- func CleanCatTSV(filename string, sorts ...string) error
- func ConfigFromDataValues(dt *Table, hdrs []string, rec [][]string) error
- func ConfigFromHeaders(dt *Table, hdrs []string, rec [][]string) error
- func ConfigFromTableHeaders(dt *Table, hdrs []string) error
- func DetectTableHeaders(hdrs []string) bool
- func InferDataType(str string) reflect.Kind
- func InsertColumn[T tensor.DataTypes](dt *Table, name string, idx int, cellSizes ...int) tensor.Tensor
- func ShapeFromString(dims string) []int
- func TableColumnType(nm string) (reflect.Kind, string)
- func TableHeaderChar(typ reflect.Kind) byte
- func UpdateSliceTable(st any, dt *Table)
- type Columns
- type FilterFunc
- type Table
- func (dt *Table) AddColumn(name string, tsr tensor.Values) error
- func (dt *Table) AddColumnOfType(name string, typ reflect.Kind, cellSizes ...int) tensor.Tensor
- func (dt *Table) AddFloat32Column(name string, cellSizes ...int) *tensor.Float32
- func (dt *Table) AddFloat64Column(name string, cellSizes ...int) *tensor.Float64
- func (dt *Table) AddIntColumn(name string, cellSizes ...int) *tensor.Int
- func (dt *Table) AddRows(n int) *Table
- func (dt *Table) AddStringColumn(name string, cellSizes ...int) *tensor.String
- func (dt *Table) AppendRows(dt2 *Table)
- func (dt *Table) Clone() *Table
- func (dt *Table) CloseLog()
- func (dt *Table) Column(name string) *tensor.Rows
- func (dt *Table) ColumnByIndex(idx int) *tensor.Rows
- func (dt *Table) ColumnIndex(name string) int
- func (dt *Table) ColumnIndexList(names ...string) []int
- func (dt *Table) ColumnList(names ...string) []tensor.Tensor
- func (dt *Table) ColumnName(i int) string
- func (dt *Table) ColumnTry(name string) (*tensor.Rows, error)
- func (dt *Table) ConfigFromTable(ft *Table) error
- func (dt *Table) DeleteAll()
- func (dt *Table) DeleteColumnByIndex(i, j int)
- func (dt *Table) DeleteColumnName(name string) bool
- func (dt *Table) DeleteRows(at, n int)
- func (dt *Table) Filter(filterer func(dt *Table, row int) bool)
- func (dt *Table) FilterString(columnName string, str string, opts tensor.StringMatch) error
- func (dt *Table) IndexesFromTensor(ix *tensor.Rows)
- func (dt *Table) IndexesNeeded()
- func (dt *Table) Init()
- func (dt *Table) InsertColumn(idx int, name string, tsr tensor.Values) error
- func (dt *Table) InsertKeyColumns(args ...string) *Table
- func (dt *Table) InsertRows(at, n int) *Table
- func (dt *Table) IsValidRow(row int) error
- func (dt *Table) Metadata() *metadata.Data
- func (dt *Table) New() *Table
- func (dt *Table) NumColumns() int
- func (dt *Table) NumRows() int
- func (dt *Table) OpenCSV(filename fsx.Filename, delim tensor.Delims) error
- func (dt *Table) OpenFS(fsys fs.FS, filename string, delim tensor.Delims) error
- func (dt *Table) OpenLog(filename string, delim tensor.Delims) error
- func (dt *Table) Permuted()
- func (dt *Table) ReadCSV(r io.Reader, delim tensor.Delims) error
- func (dt *Table) ReadCSVRow(rec []string, row int)
- func (dt *Table) RowIndex(idx int) int
- func (dt *Table) SaveCSV(filename fsx.Filename, delim tensor.Delims, headers bool) error
- func (dt *Table) Sequential()
- func (dt *Table) SetNumRows(rows int) *Table
- func (dt *Table) SetNumRowsToMax()
- func (dt *Table) SortColumn(columnName string, ascending bool) error
- func (dt *Table) SortColumnIndexes(ascending, stable bool, colIndexes ...int)
- func (dt *Table) SortColumns(ascending, stable bool, columns ...string)
- func (dt *Table) SortFunc(cmp func(dt *Table, i, j int) int)
- func (dt *Table) SortIndexes()
- func (dt *Table) SortStableFunc(cmp func(dt *Table, i, j int) int)
- func (dt *Table) Swap(i, j int)
- func (dt *Table) TableHeaders() []string
- func (dt *Table) ValidIndexes()
- func (dt *Table) WriteCSV(w io.Writer, delim tensor.Delims, headers bool) error
- func (dt *Table) WriteCSVHeaders(w io.Writer, delim tensor.Delims) (int, error)
- func (dt *Table) WriteCSVRow(w io.Writer, row int, delim tensor.Delims) error
- func (dt *Table) WriteCSVRowWriter(cw *csv.Writer, row int, ncol int) error
- func (dt *Table) WriteToLog() error
Constants ¶
const ( // Headers is passed to CSV methods for the headers arg, to use headers // that capture full type and tensor shape information. Headers = true // NoHeaders is passed to CSV methods for the headers arg, to not use headers NoHeaders = false )
Variables ¶
var (
ErrLogNoNewRows = errors.New("no new rows to write")
)
var TableHeaderToType = map[byte]reflect.Kind{ '$': reflect.String, '%': reflect.Float32, '#': reflect.Float64, '|': reflect.Int, '^': reflect.Bool, }
TableHeaderToType maps special header characters to data type
Functions ¶
func AddColumn ¶
AddColumn adds a new column to the table, of given type and column name (which must be unique). If no cellSizes are specified, it holds scalar values, otherwise the cells are n-dimensional tensors of given size.
func CleanCatTSV ¶
CleanCatTSV cleans a TSV file formed by concatenating multiple files together. Removes redundant headers and then sorts by given set of columns.
func ConfigFromDataValues ¶
ConfigFromDataValues configures a Table based on data types inferred from the string representation of given records, using header names if present.
func ConfigFromHeaders ¶
ConfigFromHeaders attempts to configure Table based on the headers. for non-table headers, data is examined to determine types.
func ConfigFromTableHeaders ¶
ConfigFromTableHeaders attempts to configure a Table based on special table headers
func DetectTableHeaders ¶
DetectTableHeaders looks for special header characters -- returns true if found
func InferDataType ¶
InferDataType returns the inferred data type for the given string only deals with float64, int, and string types
func InsertColumn ¶
func InsertColumn[T tensor.DataTypes](dt *Table, name string, idx int, cellSizes ...int) tensor.Tensor
InsertColumn inserts a new column to the table, of given type and column name (which must be unique), at given index. If no cellSizes are specified, it holds scalar values, otherwise the cells are n-dimensional tensors of given size.
func ShapeFromString ¶
ShapeFromString parses string representation of shape as N:d,d,..
func TableColumnType ¶
TableColumnType parses the column header for special table type information
func TableHeaderChar ¶
TableHeaderChar returns the special header character based on given data type
func UpdateSliceTable ¶
UpdateSliceTable updates given Table with data from the given slice of structs, which must be the same type as used to configure the table
Types ¶
type Columns ¶
type Columns struct { keylist.List[string, tensor.Values] // number of rows, which is enforced to be the size of the // outermost row dimension of the column tensors. Rows int `edit:"-"` }
Columns is the underlying column list and number of rows for Table. Each column is a raw tensor.Values tensor, and Table provides a tensor.Rows indexed view onto the Columns.
func (*Columns) AddColumn ¶
AddColumn adds the given tensor (as a tensor.Values) as a column, returning an error and not adding if the name is not unique. Automatically adjusts the shape to fit the current number of rows, (setting Rows if this is the first column added) and calls the metadata SetName with column name.
func (*Columns) AppendRows ¶
AppendRows appends shared columns in both tables with input table rows.
func (*Columns) InsertColumn ¶
InsertColumn inserts the given tensor as a column 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.
func (*Columns) SetNumRows ¶
SetNumRows sets the number of rows in the table, across all columns. It is safe to set this to 0. For incrementally growing tables (e.g., a log) it is best to first set the anticipated full size, which allocates the full amount of memory, and then set to 0 and grow incrementally.
type FilterFunc ¶
FilterFunc is a function used for filtering that returns true if Table row should be included in the current filtered view of the table, and false if it should be removed.
type Table ¶
type Table struct { // Columns has the list of column tensor data for this table. // Different tables can provide different indexed views onto the same Columns. Columns *Columns // Indexes are the indexes into Tensor rows, with nil = sequential. // Only set if order is different from default sequential order. // These indexes are shared into the `tensor.Rows` Column values // to provide a coordinated indexed view into the underlying data. Indexes []int // Meta is misc metadata for the table. Use lower-case key names // following the struct tag convention: // - name string = name of table // - doc string = documentation, description // - read-only bool = gui is read-only // - precision int = n for precision to write out floats in csv. Meta metadata.Data }
Table is a table of Tensor columns aligned by a common outermost row dimension. Use the Table.Column (by name) and Table.ColumnIndex methods to obtain a tensor.Rows view of the column, using the shared [Table.Indexes] of the Table. Thus, a coordinated sorting and filtered view of the column data is automatically available for any of the tensor package functions that use tensor.Tensor as the one common data representation for all operations. Tensor Columns are always raw value types and support SubSpace operations on cells.
func New ¶
New returns a new Table with its own (empty) set of Columns. Can pass an optional name which calls metadata SetName.
func NewSliceTable ¶
NewSliceTable returns a new Table with data from the given slice of structs.
func NewView ¶
NewView returns a new Table with its own Rows view into the same underlying set of Column tensor data as the source table. Indexes are copied from the existing table -- use Sequential to reset to full sequential view.
func (*Table) AddColumn ¶
AddColumn adds the given tensor.Values as a column to the table, returning an error and not adding if the name is not unique. Automatically adjusts the shape to fit the current number of rows.
func (*Table) AddColumnOfType ¶
AddColumnOfType adds a new scalar column to the table, of given reflect type, column name (which must be unique), If no cellSizes are specified, it holds scalar values, otherwise the cells are n-dimensional tensors of given size. Supported types include string, bool (for tensor.Bool), float32, float64, int, int32, and byte.
func (*Table) AddFloat32Column ¶
AddFloat32Column adds a new float32 column with given name. If no cellSizes are specified, it holds scalar values, otherwise the cells are n-dimensional tensors of given size.
func (*Table) AddFloat64Column ¶
AddFloat64Column adds a new float64 column with given name. If no cellSizes are specified, it holds scalar values, otherwise the cells are n-dimensional tensors of given size.
func (*Table) AddIntColumn ¶
AddIntColumn adds a new int column with given name. If no cellSizes are specified, it holds scalar values, otherwise the cells are n-dimensional tensors of given size.
func (*Table) AddRows ¶
AddRows adds n rows to end of underlying Table, and to the indexes in this view.
func (*Table) AddStringColumn ¶
AddStringColumn adds a new String column with given name. If no cellSizes are specified, it holds scalar values, otherwise the cells are n-dimensional tensors of given size.
func (*Table) AppendRows ¶
AppendRows appends shared columns in both tables with input table rows.
func (*Table) Clone ¶
Clone returns a complete copy of this table, including cloning the underlying Columns tensors, and the current [Table.Indexes]. See also Table.New to flatten the current indexes.
func (*Table) CloseLog ¶
func (dt *Table) CloseLog()
CloseLog closes the log file opened by Table.OpenLog.
func (*Table) Column ¶
Column returns the tensor with given column name, as a tensor.Rows with the shared [Table.Indexes] from this table. It is best practice to access columns by name, and direct access through [Table.Columns] does not provide the shared table-wide Indexes. Returns nil if not found.
func (*Table) ColumnByIndex ¶
ColumnIndex returns the tensor at the given column index, as a tensor.Rows with the shared [Table.Indexes] from this table. It is best practice to instead access columns by name using Table.Column. Direct access through [Table.Columns} does not provide the shared table-wide Indexes. Will panic if out of range.
func (*Table) ColumnIndex ¶
ColumnIndex returns the index for given column name.
func (*Table) ColumnIndexList ¶
ColumnIndexList returns a list of indexes to columns of given names.
func (*Table) ColumnList ¶
ColumnList returns a list of tensors with given column names, as tensor.Rows with the shared [Table.Indexes] from this table.
func (*Table) ColumnName ¶
ColumnName returns the name of given column.
func (*Table) ColumnTry ¶
ColumnTry is a version of Table.Column that also returns an error if the column name is not found, for cases when error is needed.
func (*Table) ConfigFromTable ¶
ConfigFromTable configures the columns of this table according to the values in the first two columns of given format table, conventionally named Name, Type (but names are not used), which must be of the string type.
func (*Table) DeleteAll ¶
func (dt *Table) DeleteAll()
DeleteAll deletes all columns, does full reset.
func (*Table) DeleteColumnByIndex ¶
DeleteColumnIndex deletes column within the index range [i:j].
func (*Table) DeleteColumnName ¶
DeleteColumnName deletes column of given name. returns false if not found.
func (*Table) DeleteRows ¶
DeleteRows deletes n rows of Indexes starting at given index in the list of indexes. This does not affect the underlying tensor data; To create an actual in-memory ordering with rows deleted, use Table.New.
func (*Table) Filter ¶
Filter filters the indexes into our Table using given Filter function. The Filter function operates directly on row numbers into the Table as these row numbers have already been projected through the indexes.
func (*Table) FilterString ¶
FilterString filters the indexes using string values in column compared to given string. Includes rows with matching values unless the Exclude option is set. If Contains option is set, it only checks if row contains string; if IgnoreCase, ignores case, otherwise filtering is case sensitive. Uses first cell from higher dimensions. Returns error if column name not found.
func (*Table) IndexesFromTensor ¶
IndexesFromTensor copies Indexes from the given tensor.Rows tensor, including if they are nil. This allows column-specific Sort, Filter and other such methods to be applied to the entire table.
func (*Table) IndexesNeeded ¶
func (dt *Table) IndexesNeeded()
IndexesNeeded is called prior to an operation that needs actual indexes, e.g., Sort, Filter. If Indexes == nil, they are set to all rows, otherwise current indexes are left as is. Use Sequential, then IndexesNeeded to ensure all rows are represented.
func (*Table) InsertColumn ¶
InsertColumn inserts the given tensor.Values 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.
func (*Table) InsertKeyColumns ¶
InsertKeyColumns returns a copy of the given Table with new columns having given values, inserted at the start, used as legend keys etc. args must be in pairs: column name, value. All rows get the same value.
func (*Table) InsertRows ¶
InsertRows adds n rows to end of underlying Table, and to the indexes starting at given index in this view, providing an efficient insertion operation that only exists in the indexed view. To create an in-memory ordering, use Table.New.
func (*Table) IsValidRow ¶
IsValidRow returns error if the row is invalid, if error checking is needed.
func (*Table) New ¶
New returns a new table with column data organized according to the indexes. If Indexes are nil, a clone of the current tensor is returned but this function is only sensible if there is an indexed view in place.
func (*Table) NumColumns ¶
NumColumns returns the number of columns.
func (*Table) NumRows ¶
NumRows returns the number of rows, which is the number of Indexes if present, else actual number of [Columns.Rows].
func (*Table) OpenCSV ¶
OpenCSV reads a table from a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg), using the Go standard encoding/csv reader conforming to the official CSV standard. If the table does not currently have any columns, the first row of the file is assumed to be headers, and columns are constructed therefrom. If the file was saved from table with headers, then these have full configuration information for tensor type and dimensionality. If the table DOES have existing columns, then those are used robustly for whatever information fits from each row of the file.
func (*Table) OpenFS ¶
OpenFS is the version of Table.OpenCSV that uses an fs.FS filesystem.
func (*Table) OpenLog ¶
OpenLog opens a log file for this table, which supports incremental output of table data as it is generated, using the standard Table.SaveCSV output formatting, using given delimiter between values on a line. Call Table.WriteToLog to write any new data rows to the open log file, and Table.CloseLog to close the file.
func (*Table) Permuted ¶
func (dt *Table) Permuted()
Permuted sets indexes to a permuted order -- if indexes already exist then existing list of indexes is permuted, otherwise a new set of permuted indexes are generated
func (*Table) ReadCSV ¶
ReadCSV reads a table from a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg), using the Go standard encoding/csv reader conforming to the official CSV standard. If the table does not currently have any columns, the first row of the file is assumed to be headers, and columns are constructed therefrom. If the file was saved from table with headers, then these have full configuration information for tensor type and dimensionality. If the table DOES have existing columns, then those are used robustly for whatever information fits from each row of the file.
func (*Table) ReadCSVRow ¶
ReadCSVRow reads a record of CSV data into given row in table
func (*Table) RowIndex ¶
RowIndex returns the actual index into underlying tensor row based on given index value. If Indexes == nil, index is passed through.
func (*Table) SaveCSV ¶
SaveCSV writes a table to a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg). If headers = true then generate column headers that capture the type and tensor cell geometry of the columns, enabling full reloading of exactly the same table format and data (recommended). Otherwise, only the data is written.
func (*Table) Sequential ¶
func (dt *Table) Sequential()
Sequential sets Indexes to nil, resulting in sequential row-wise access into tensor.
func (*Table) SetNumRows ¶
SetNumRows sets the number of rows in the table, across all columns. If rows = 0 then effective number of rows in tensors is 1, as this dim cannot be 0. If indexes are in place and rows are added, indexes for the new rows are added.
func (*Table) SetNumRowsToMax ¶
func (dt *Table) SetNumRowsToMax()
SetNumRowsToMax gets the current max number of rows across all the column tensors, and sets the number of rows to that. This will automatically pad shorter columns so they all have the same number of rows. If a table has columns that are not fully under its own control, they can change size, so this reestablishes a common row dimension.
func (*Table) SortColumn ¶
SortColumn sorts the indexes into our Table according to values in given column, using either ascending or descending order, (use tensor.Ascending or tensor.Descending for self-documentation). Uses first cell of higher dimensional data. Returns error if column name not found.
func (*Table) SortColumnIndexes ¶
SortColumnIndexes sorts the indexes into our Table according to values in given list of column indexes, using either ascending or descending order for all of the columns. Uses first cell of higher dimensional data.
func (*Table) SortColumns ¶
SortColumns sorts the indexes into our Table according to values in given column names, using either ascending or descending order, (use tensor.Ascending or tensor.Descending for self-documentation, and optionally using a stable sort. Uses first cell of higher dimensional data.
func (*Table) SortFunc ¶
SortFunc sorts the indexes into our Table using given compare function. The compare function operates directly on row numbers into the Table as these row numbers have already been projected through the indexes. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
func (*Table) SortIndexes ¶
func (dt *Table) SortIndexes()
SortIndexes sorts the indexes into our Table directly in numerical order, producing the native ordering, while preserving any filtering that might have occurred.
func (*Table) SortStableFunc ¶
SortStableFunc stably sorts the indexes into our Table using given compare function. The compare function operates directly on row numbers into the Table as these row numbers have already been projected through the indexes. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b. It is *essential* that it always returns 0 when the two are equal for the stable function to actually work.
func (*Table) TableHeaders ¶
TableHeaders generates special header strings from the table with full information about type and tensor cell dimensionality.
func (*Table) ValidIndexes ¶
func (dt *Table) ValidIndexes()
ValidIndexes deletes all invalid indexes from the list. Call this if rows (could) have been deleted from table.
func (*Table) WriteCSV ¶
WriteCSV writes only rows in table idx view to a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg). If headers = true then generate column headers that capture the type and tensor cell geometry of the columns, enabling full reloading of exactly the same table format and data (recommended). Otherwise, only the data is written.
func (*Table) WriteCSVHeaders ¶
WriteCSVHeaders writes headers to a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg). Returns number of columns in header
func (*Table) WriteCSVRow ¶
WriteCSVRow writes given row to a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg)
func (*Table) WriteCSVRowWriter ¶
WriteCSVRowWriter uses csv.Writer to write one row
func (*Table) WriteToLog ¶
WriteToLog writes any accumulated rows in the table to the file opened by Table.OpenLog. A Header row is written for the first output. If the current number of rows is less than the last number of rows, all of those rows are written under the assumption that the rows were reset via Table.SetNumRows. Returns error for any failure, including ErrLogNoNewRows if no new rows are available to write.