MCPcopy Create free account
hub / github.com/cogentcore/core / AggsToTableCopy

Method AggsToTableCopy

tensor/table/splits.go:455–509  ·  view source on GitHub ↗

AggsToTableCopy returns a Table containing this Splits' aggregate data and a copy of the first row of data for each split for all non-agg cols, which is useful for recording other data that goes along with aggregated values. Must have Levels and Aggs all created as in the split.Agg* methods. if colN

(colName bool)

Source from the content-addressed store, hash-verified

453// is just the corresponding agg column name -- otherwise it also includes
454// the name of the aggregation function with a : divider (e.g., Name:Mean)
455func (spl *Splits) AggsToTableCopy(colName bool) *Table {
456 nsp := len(spl.Splits)
457 if nsp == 0 {
458 return nil
459 }
460 dt := spl.Splits[0].Table
461 st := NewTable().SetNumRows(nsp)
462 exmap := make(map[string]struct{})
463 for _, cn := range spl.Levels {
464 st.AddStringColumn(cn)
465 exmap[cn] = struct{}{}
466 }
467 for _, ag := range spl.Aggs {
468 col := dt.Columns[ag.ColumnIndex]
469 an := dt.ColumnNames[ag.ColumnIndex]
470 exmap[an] = struct{}{}
471 if colName == AddAggName {
472 an += ":" + ag.Name
473 }
474 st.AddFloat64TensorColumn(an, col.Shape().Sizes[1:], col.Shape().Names[1:]...)
475 }
476 var cpcol []string
477 for _, cn := range dt.ColumnNames {
478 if _, ok := exmap[cn]; !ok {
479 cpcol = append(cpcol, cn)
480 col := dt.ColumnByName(cn)
481 st.AddColumn(col.Clone(), cn)
482 }
483 }
484 for si, sidx := range spl.Splits {
485 cidx := 0
486 for ci := range spl.Levels {
487 col := st.Columns[cidx]
488 col.SetString1D(si, spl.Values[si][ci])
489 cidx++
490 }
491 for _, ag := range spl.Aggs {
492 col := st.Columns[cidx]
493 _, csz := col.RowCellSize()
494 sti := si * csz
495 av := ag.Aggs[si]
496 for j, a := range av {
497 col.SetFloat1D(sti+j, a)
498 }
499 cidx++
500 }
501 if len(sidx.Indexes) > 0 {
502 stidx := sidx.Indexes[0]
503 for _, cn := range cpcol {
504 st.CopyCell(cn, si, dt, cn, stidx)
505 }
506 }
507 }
508 return st
509}
510
511// Less calls the LessFunc for sorting
512func (spl *Splits) Less(i, j int) bool {

Callers

nothing calls this directly

Calls 12

AddStringColumnMethod · 0.80
ColumnByNameMethod · 0.80
AddColumnMethod · 0.80
CopyCellMethod · 0.80
NewTableFunction · 0.70
SetNumRowsMethod · 0.65
ShapeMethod · 0.65
CloneMethod · 0.65
SetString1DMethod · 0.65
RowCellSizeMethod · 0.65
SetFloat1DMethod · 0.65

Tested by

no test coverage detected