tensorcore

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 28 Imported by: 13

README

tensorcore

tensorcore provides GUI Views of table.Table and tensor.Tensor structures as Cogent Core Widgets.

Add this to import to get these views to be registered with the Cogent Core Value system:

	_ "cogentcore.org/core/tensor/tensorcore" // include to get GUI views
  • Table provides a row-and-column tabular GUI interface, similar to a spreadsheet, for viewing and editing Table data. Any higher-dimensional tensor columns are shown as TensorGrid elements that can be clicked to open a TensorView editor with actual numeric values in a similar spreadsheet-like GUI.

  • TensorView provides a spreadsheet-like GUI for viewing and editing tensor data.

  • TensorGrid provides a 2D colored grid display of tensor data, collapsing any higher dimensions down to 2D. Different core.ColorMaps can be used to translate values into colors.

Documentation

Overview

Package tensorcore provides GUI Views of table Table and Tensor structures using the Cogent Core views framework.

* Table provides a row-and-column tabular GUI interface, similar to a spreadsheet, for viewing and editing Table data. Any higher-dimensional tensor columns are shown as TensorGrid elements that can be clicked to open a TensorView editor with actual numeric values in a similar spreadsheet- like GUI.

* TensorView provides a spreadsheet-like GUI for viewing and editing tensor data.

* TensorGrid provides a 2D colored grid display of tensor data, collapsing any higher dimensions down to 2D. Different core.ColorMaps can be used to translate values into colors.

Package tensorcore provides GUI Cogent Core widgets for tensor types.

Package tensorcore provides GUI Cogent Core widgets for tensor types.

Index

Constants

View Source
const LabelSpace = float32(8)

Variables

This section is empty.

Functions

This section is empty.

Types

type SimMatButton

type SimMatButton struct {
	core.Button
	SimMat *simat.SimMat
}

SimMatValue presents a button that pulls up the SimMatGrid viewer for a table.Table.

func NewSimMatButton

func NewSimMatButton(parent ...tree.Node) *SimMatButton

NewSimMatButton returns a new SimMatButton with the given optional parent: SimMatValue presents a button that pulls up the SimMatGrid viewer for a table.Table.

func (*SimMatButton) Init

func (tb *SimMatButton) Init()

func (*SimMatButton) SetSimMat

func (t *SimMatButton) SetSimMat(v *simat.SimMat) *SimMatButton

SetSimMat sets the [SimMatButton.SimMat]

func (*SimMatButton) WidgetValue

func (tb *SimMatButton) WidgetValue() any

type SimMatGrid

type SimMatGrid struct {
	TensorGrid

	// the similarity / distance matrix
	SimMat *simat.SimMat `set:"-"`
	// contains filtered or unexported fields
}

SimMatGrid is a widget that displays a similarity / distance matrix with tensor values as a grid of colored squares, and labels for rows and columns.

func NewSimMatGrid

func NewSimMatGrid(parent ...tree.Node) *SimMatGrid

NewSimMatGrid returns a new SimMatGrid with the given optional parent: SimMatGrid is a widget that displays a similarity / distance matrix with tensor values as a grid of colored squares, and labels for rows and columns.

func (*SimMatGrid) Init

func (tg *SimMatGrid) Init()

Defaults sets defaults for values that are at nonsensical initial values

func (*SimMatGrid) Render

func (tg *SimMatGrid) Render()

func (*SimMatGrid) SetSimMat

func (tg *SimMatGrid) SetSimMat(smat *simat.SimMat) *SimMatGrid

SetSimMat sets the similarity matrix and triggers a display update

func (*SimMatGrid) SizeLabel

func (tg *SimMatGrid) SizeLabel(lbs []string, col bool) (minBlank, ngps int, sz math32.Vector2)

func (*SimMatGrid) SizeUp added in v0.3.3

func (tg *SimMatGrid) SizeUp()

type Table

type Table struct {
	core.ListBase

	// the idx view of the table that we're a view of
	Table *table.IndexView `set:"-"`

	// overall display options for tensor display
	TensorDisplay TensorDisplay `set:"-"`

	// per column tensor display params
	ColumnTensorDisplay map[int]*TensorDisplay `set:"-"`

	// per column blank tensor values
	ColumnTensorBlank map[int]*tensor.Float64 `set:"-"`

	// number of columns in table (as of last update)
	NCols int `edit:"-"`

	// current sort index
	SortIndex int

	// whether current sort order is descending
	SortDescending bool

	//	blank values for out-of-range rows
	BlankString string
	BlankFloat  float64
	// contains filtered or unexported fields
}

Table provides a GUI widget for representing table.Table values.

func NewTable

func NewTable(parent ...tree.Node) *Table

NewTable returns a new Table with the given optional parent: Table provides a GUI widget for representing table.Table values.

func (*Table) AsyncUpdateTable added in v0.2.3

func (tb *Table) AsyncUpdateTable()

AsyncUpdateTable updates the display for asynchronous updating from other goroutines. Also updates indexview (calling Sequential).

func (*Table) ColTensorBlank

func (tb *Table) ColTensorBlank(cidx int, col tensor.Tensor) *tensor.Float64

ColTensorBlank returns tensor blanks for given tensor col

func (*Table) CopySelectToMime

func (tb *Table) CopySelectToMime() mimedata.Mimes

CopySelectToMime copies selected rows to mime data

func (*Table) DeleteAt added in v0.2.1

func (tb *Table) DeleteAt(idx int)

DeleteAt deletes element at given index from slice

func (*Table) FromMimeData

func (tb *Table) FromMimeData(md mimedata.Mimes) [][]string

FromMimeData returns records from csv of mime data

func (*Table) GetColumnTensorDisplay

func (tb *Table) GetColumnTensorDisplay(col int) *TensorDisplay

GetColumnTensorDisplay returns tensor display parameters for this column either the overall defaults or the per-column if set

func (*Table) HasStyler added in v0.2.1

func (tb *Table) HasStyler() bool

func (*Table) Init

func (tb *Table) Init()

func (*Table) MakeHeader

func (tb *Table) MakeHeader(p *tree.Plan)

func (*Table) MakeRow

func (tb *Table) MakeRow(p *tree.Plan, i int)

func (*Table) MakeToolbar

func (tb *Table) MakeToolbar(p *tree.Plan)

func (*Table) MimeDataType

func (tb *Table) MimeDataType() string

func (*Table) NewAt added in v0.2.1

func (tb *Table) NewAt(idx int)

NewAt inserts a new blank element at given index in the slice -- -1 means the end

func (*Table) PasteAssign

func (tb *Table) PasteAssign(md mimedata.Mimes, idx int)

PasteAssign assigns mime data (only the first one!) to this idx

func (*Table) PasteAtIndex

func (tb *Table) PasteAtIndex(md mimedata.Mimes, idx int)

PasteAtIndex inserts object(s) from mime data at (before) given slice index adds to end of table

func (*Table) RowFirstVisWidget

func (tb *Table) RowFirstVisWidget(row int) (*core.WidgetBase, bool)

RowFirstVisWidget returns the first visible widget for given row (could be index or not) -- false if out of range

func (*Table) RowGrabFocus

func (tb *Table) RowGrabFocus(row int) *core.WidgetBase

RowGrabFocus grabs the focus for the first focusable widget in given row -- returns that element or nil if not successful -- note: grid must have already rendered for focus to be grabbed!

func (*Table) RowWidgetNs

func (tb *Table) RowWidgetNs() (nWidgPerRow, idxOff int)

RowWidgetNs returns number of widgets per row and offset for index label

func (*Table) SelectedColumnStrings

func (tb *Table) SelectedColumnStrings(colName string) []string

SelectedColumnStrings returns the string values of given column name.

func (*Table) SetBlankFloat

func (t *Table) SetBlankFloat(v float64) *Table

SetBlankFloat sets the [Table.BlankFloat]

func (*Table) SetBlankString

func (t *Table) SetBlankString(v string) *Table

SetBlankString sets the [Table.BlankString]:

blank values for out-of-range rows

func (*Table) SetColumnTensorDisplay

func (tb *Table) SetColumnTensorDisplay(col int) *TensorDisplay

SetColumnTensorDisplay sets per-column tensor display params and returns them if already set, just returns them

func (*Table) SetIndexView

func (tb *Table) SetIndexView(ix *table.IndexView) *Table

SetIndexView sets the source IndexView of a table (using a copy so original is not modified) and then configures the display

func (*Table) SetNCols

func (t *Table) SetNCols(v int) *Table

SetNCols sets the [Table.NCols]: number of columns in table (as of last update)

func (*Table) SetSlice added in v0.3.1

func (tb *Table) SetSlice(sl any) *Table

SetSlice sets the source table to a table.NewSliceTable from the given slice.

func (*Table) SetSortDescending

func (t *Table) SetSortDescending(v bool) *Table

SetSortDescending sets the [Table.SortDescending]: whether current sort order is descending

func (*Table) SetSortFieldName

func (tb *Table) SetSortFieldName(nm string)

SetSortField sets sorting to happen on given field and direction -- see SortFieldName for details

func (*Table) SetSortIndex

func (t *Table) SetSortIndex(v int) *Table

SetSortIndex sets the [Table.SortIndex]: current sort index

func (*Table) SetTable

func (tb *Table) SetTable(et *table.Table) *Table

SetTable sets the source table that we are viewing, using a sequential IndexView and then configures the display

func (*Table) SizeFinal

func (tb *Table) SizeFinal()

func (*Table) SliceHeader

func (tb *Table) SliceHeader() *core.Frame

SliceHeader returns the Frame header for slice grid

func (*Table) SliceIndex

func (tb *Table) SliceIndex(i int) (si, vi int, invis bool)

func (*Table) SortFieldName

func (tb *Table) SortFieldName() string

SortFieldName returns the name of the field being sorted, along with :up or :down depending on descending

func (*Table) SortSliceAction

func (tb *Table) SortSliceAction(fldIndex int)

SortSliceAction sorts the slice for given field index -- toggles ascending vs. descending if already sorting on this dimension

func (*Table) StyleRow

func (tb *Table) StyleRow(w core.Widget, idx, fidx int)

func (*Table) StyleValue

func (tb *Table) StyleValue(w core.Widget, s *styles.Style, row, col int)

StyleValue performs additional value widget styling

func (*Table) TensorDisplayAction

func (tb *Table) TensorDisplayAction(fldIndex int)

TensorDisplayAction allows user to select tensor display options for column pass -1 for global params for the entire table

func (*Table) UpdateMaxWidths

func (tb *Table) UpdateMaxWidths()

func (*Table) UpdateSliceSize

func (tb *Table) UpdateSliceSize() int

type TableButton

type TableButton struct {
	core.Button
	Table *table.Table
}

TableButton presents a button that pulls up the Table viewer for a table.Table.

func NewTableButton

func NewTableButton(parent ...tree.Node) *TableButton

NewTableButton returns a new TableButton with the given optional parent: TableButton presents a button that pulls up the Table viewer for a table.Table.

func (*TableButton) Init

func (tb *TableButton) Init()

func (*TableButton) SetTable

func (t *TableButton) SetTable(v *table.Table) *TableButton

SetTable sets the [TableButton.Table]

func (*TableButton) WidgetValue

func (tb *TableButton) WidgetValue() any

type TensorButton

type TensorButton struct {
	core.Button
	Tensor tensor.Tensor
}

TensorButton represents a Tensor with a button for making a TensorGrid viewer for an tensor.Tensor.

func NewTensorButton

func NewTensorButton(parent ...tree.Node) *TensorButton

NewTensorButton returns a new TensorButton with the given optional parent: TensorButton represents a Tensor with a button for making a TensorGrid viewer for an tensor.Tensor.

func (*TensorButton) Init

func (tb *TensorButton) Init()

func (*TensorButton) SetTensor

func (t *TensorButton) SetTensor(v tensor.Tensor) *TensorButton

SetTensor sets the [TensorButton.Tensor]

func (*TensorButton) WidgetValue

func (tb *TensorButton) WidgetValue() any

type TensorDisplay

type TensorDisplay struct {
	TensorLayout

	// range to plot
	Range minmax.Range64 `display:"inline"`

	// if not using fixed range, this is the actual range of data
	MinMax minmax.F64 `display:"inline"`

	// the name of the color map to use in translating values to colors
	ColorMap core.ColorMapName

	// what proportion of grid square should be filled by color block -- 1 = all, .5 = half, etc
	GridFill float32 `min:"0.1" max:"1" step:"0.1" default:"0.9,1"`

	// amount of extra space to add at dimension boundaries, as a proportion of total grid size
	DimExtra float32 `min:"0" max:"1" step:"0.02" default:"0.1,0.3"`

	// minimum size for grid squares -- they will never be smaller than this
	GridMinSize float32

	// maximum size for grid squares -- they will never be larger than this
	GridMaxSize float32

	// total preferred display size along largest dimension.
	// grid squares will be sized to fit within this size,
	// subject to harder GridMin / Max size constraints
	TotPrefSize float32

	// font size in standard point units for labels (e.g., SimMat)
	FontSize float32

	// our gridview, for update method
	GridView *TensorGrid `copier:"-" json:"-" xml:"-" display:"-"`
}

TensorDisplay are options for displaying tensors

func (*TensorDisplay) Defaults

func (td *TensorDisplay) Defaults()

Defaults sets defaults for values that are at nonsensical initial values

func (*TensorDisplay) FromMeta

func (td *TensorDisplay) FromMeta(tsr tensor.Tensor)

FromMeta sets display options from Tensor meta-data

type TensorEditor added in v0.3.3

type TensorEditor struct {
	core.ListBase

	// the tensor that we're a view of
	Tensor tensor.Tensor `set:"-"`

	// overall layout options for tensor display
	Layout TensorLayout `set:"-"`

	// number of columns in table (as of last update)
	NCols int `edit:"-"`

	//	blank values for out-of-range rows
	BlankString string
	BlankFloat  float64
	// contains filtered or unexported fields
}

TensorEditor provides a GUI widget for representing tensor.Tensor values.

func NewTensorEditor added in v0.3.3

func NewTensorEditor(parent ...tree.Node) *TensorEditor

NewTensorEditor returns a new TensorEditor with the given optional parent: TensorEditor provides a GUI widget for representing tensor.Tensor values.

func (*TensorEditor) ColumnHeader added in v0.3.3

func (tb *TensorEditor) ColumnHeader(col int) string

func (*TensorEditor) CopySelectToMime added in v0.3.3

func (tb *TensorEditor) CopySelectToMime() mimedata.Mimes

CopySelectToMime copies selected rows to mime data

func (*TensorEditor) FromMimeData added in v0.3.3

func (tb *TensorEditor) FromMimeData(md mimedata.Mimes) [][]string

FromMimeData returns records from csv of mime data

func (*TensorEditor) HasStyler added in v0.3.3

func (tb *TensorEditor) HasStyler() bool

func (*TensorEditor) Init added in v0.3.3

func (tb *TensorEditor) Init()

func (*TensorEditor) MakeHeader added in v0.3.3

func (tb *TensorEditor) MakeHeader(p *tree.Plan)

func (*TensorEditor) MakeRow added in v0.3.3

func (tb *TensorEditor) MakeRow(p *tree.Plan, i int)

func (*TensorEditor) MakeToolbar added in v0.3.3

func (tb *TensorEditor) MakeToolbar(p *tree.Plan)

func (*TensorEditor) MimeDataType added in v0.3.3

func (tb *TensorEditor) MimeDataType() string

func (*TensorEditor) OpenCSV added in v0.3.3

func (tb *TensorEditor) OpenCSV(filename core.Filename) error

OpenTSV reads a tensor from a tab-separated-values (TSV) file. using the Go standard encoding/csv reader conforming to the official CSV standard. Reads all values and assigns as many as fit.

func (*TensorEditor) PasteAssign added in v0.3.3

func (tb *TensorEditor) PasteAssign(md mimedata.Mimes, idx int)

PasteAssign assigns mime data (only the first one!) to this idx

func (*TensorEditor) PasteAtIndex added in v0.3.3

func (tb *TensorEditor) PasteAtIndex(md mimedata.Mimes, idx int)

PasteAtIndex inserts object(s) from mime data at (before) given slice index adds to end of table

func (*TensorEditor) RowFirstVisWidget added in v0.3.3

func (tb *TensorEditor) RowFirstVisWidget(row int) (*core.WidgetBase, bool)

RowFirstVisWidget returns the first visible widget for given row (could be index or not) -- false if out of range

func (*TensorEditor) RowGrabFocus added in v0.3.3

func (tb *TensorEditor) RowGrabFocus(row int) *core.WidgetBase

RowGrabFocus grabs the focus for the first focusable widget in given row -- returns that element or nil if not successful -- note: grid must have already rendered for focus to be grabbed!

func (*TensorEditor) RowWidgetNs added in v0.3.3

func (tb *TensorEditor) RowWidgetNs() (nWidgPerRow, idxOff int)

RowWidgetNs returns number of widgets per row and offset for index label

func (*TensorEditor) SaveCSV added in v0.3.3

func (tb *TensorEditor) SaveCSV(filename core.Filename) error

SaveTSV writes a tensor to a tab-separated-values (TSV) file. Outer-most dims are rows in the file, and inner-most is column -- Reading just grabs all values and doesn't care about shape.

func (*TensorEditor) SetBlankFloat added in v0.3.3

func (t *TensorEditor) SetBlankFloat(v float64) *TensorEditor

SetBlankFloat sets the [TensorEditor.BlankFloat]

func (*TensorEditor) SetBlankString added in v0.3.3

func (t *TensorEditor) SetBlankString(v string) *TensorEditor

SetBlankString sets the [TensorEditor.BlankString]:

blank values for out-of-range rows

func (*TensorEditor) SetNCols added in v0.3.3

func (t *TensorEditor) SetNCols(v int) *TensorEditor

SetNCols sets the [TensorEditor.NCols]: number of columns in table (as of last update)

func (*TensorEditor) SetTensor added in v0.3.3

func (tb *TensorEditor) SetTensor(et tensor.Tensor) *TensorEditor

SetTensor sets the source tensor that we are viewing, and then configures the display.

func (*TensorEditor) SizeFinal added in v0.3.3

func (tb *TensorEditor) SizeFinal()

func (*TensorEditor) SliceHeader added in v0.3.3

func (tb *TensorEditor) SliceHeader() *core.Frame

SliceHeader returns the Frame header for slice grid

func (*TensorEditor) SliceIndex added in v0.3.3

func (tb *TensorEditor) SliceIndex(i int) (si, vi int, invis bool)

func (*TensorEditor) StyleRow added in v0.3.3

func (tb *TensorEditor) StyleRow(w core.Widget, idx, fidx int)

func (*TensorEditor) StyleValue added in v0.3.3

func (tb *TensorEditor) StyleValue(w core.Widget, s *styles.Style, row, col int)

StyleValue performs additional value widget styling

func (*TensorEditor) UpdateMaxWidths added in v0.3.3

func (tb *TensorEditor) UpdateMaxWidths()

func (*TensorEditor) UpdateSliceSize added in v0.3.3

func (tb *TensorEditor) UpdateSliceSize() int

type TensorGrid

type TensorGrid struct {
	core.WidgetBase

	// the tensor that we view
	Tensor tensor.Tensor `set:"-"`

	// display options
	Display TensorDisplay

	// the actual colormap
	ColorMap *colormap.Map
}

TensorGrid is a widget that displays tensor values as a grid of colored squares.

func NewTensorGrid

func NewTensorGrid(parent ...tree.Node) *TensorGrid

NewTensorGrid returns a new TensorGrid with the given optional parent: TensorGrid is a widget that displays tensor values as a grid of colored squares.

func (*TensorGrid) Color

func (tg *TensorGrid) Color(val float64) (norm float64, clr color.Color)

func (*TensorGrid) EditSettings

func (tg *TensorGrid) EditSettings()

func (*TensorGrid) EnsureColorMap

func (tg *TensorGrid) EnsureColorMap()

EnsureColorMap makes sure there is a valid color map that matches specified name

func (*TensorGrid) Init

func (tg *TensorGrid) Init()

func (*TensorGrid) MinSize

func (tg *TensorGrid) MinSize() math32.Vector2

MinSize returns minimum size based on tensor and display settings

func (*TensorGrid) OpenTensorEditor added in v0.3.3

func (tg *TensorGrid) OpenTensorEditor()

OpenTensorEditor pulls up a TensorEditor of our tensor

func (*TensorGrid) Render

func (tg *TensorGrid) Render()

func (*TensorGrid) SetColorMap

func (t *TensorGrid) SetColorMap(v *colormap.Map) *TensorGrid

SetColorMap sets the [TensorGrid.ColorMap]: the actual colormap

func (*TensorGrid) SetDisplay

func (t *TensorGrid) SetDisplay(v TensorDisplay) *TensorGrid

SetDisplay sets the [TensorGrid.Display]: display options

func (*TensorGrid) SetTensor

func (tg *TensorGrid) SetTensor(tsr tensor.Tensor) *TensorGrid

SetTensor sets the tensor. Must call Update after this.

func (*TensorGrid) SetWidgetValue

func (tg *TensorGrid) SetWidgetValue(value any) error

func (*TensorGrid) UpdateRange

func (tg *TensorGrid) UpdateRange()

func (*TensorGrid) WidgetValue

func (tg *TensorGrid) WidgetValue() any

type TensorLayout

type TensorLayout struct {

	// even-numbered dimensions are displayed as Y*X rectangles.
	// This determines along which dimension to display any remaining
	// odd dimension: OddRow = true = organize vertically along row
	// dimension, false = organize horizontally across column dimension.
	OddRow bool

	// if true, then the Y=0 coordinate is displayed from the top-down;
	// otherwise the Y=0 coordinate is displayed from the bottom up,
	// which is typical for emergent network patterns.
	TopZero bool

	// display the data as a bitmap image.  if a 2D tensor, then it will
	// be a greyscale image.  if a 3D tensor with size of either the first
	// or last dim = either 3 or 4, then it is a RGB(A) color image.
	Image bool
}

TensorLayout are layout options for displaying tensors

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL