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

Method WriteCSVRowWriter

tensor/table/io.go:476–525  ·  view source on GitHub ↗

WriteCSVRowWriter uses csv.Writer to write one row

(cw *csv.Writer, row int, ncol int)

Source from the content-addressed store, hash-verified

474
475// WriteCSVRowWriter uses csv.Writer to write one row
476func (dt *Table) WriteCSVRowWriter(cw *csv.Writer, row int, ncol int) error {
477 prec := -1
478 if ps, ok := dt.MetaData["precision"]; ok {
479 prec, _ = strconv.Atoi(ps)
480 }
481 var rec []string
482 if ncol > 0 {
483 rec = make([]string, 0, ncol)
484 } else {
485 rec = make([]string, 0)
486 }
487 rc := 0
488 for i := range dt.Columns {
489 tsr := dt.Columns[i]
490 nd := tsr.NumDims()
491 if nd == 1 {
492 vl := ""
493 if prec <= 0 || tsr.IsString() {
494 vl = tsr.String1D(row)
495 } else {
496 vl = strconv.FormatFloat(tsr.Float1D(row), 'g', prec, 64)
497 }
498 if len(rec) <= rc {
499 rec = append(rec, vl)
500 } else {
501 rec[rc] = vl
502 }
503 rc++
504 } else {
505 csh := tensor.NewShape(tsr.Shape().Sizes[1:]) // cell shape
506 tc := csh.Len()
507 for ti := 0; ti < tc; ti++ {
508 vl := ""
509 if prec <= 0 || tsr.IsString() {
510 vl = tsr.String1D(row*tc + ti)
511 } else {
512 vl = strconv.FormatFloat(tsr.Float1D(row*tc+ti), 'g', prec, 64)
513 }
514 if len(rec) <= rc {
515 rec = append(rec, vl)
516 } else {
517 rec[rc] = vl
518 }
519 rc++
520 }
521 }
522 }
523 err := cw.Write(rec)
524 return err
525}
526
527// TableHeaders generates special header strings from the table
528// with full information about type and tensor cell dimensionality.

Callers 3

WriteCSVMethod · 0.95
WriteCSVRowMethod · 0.95
WriteCSVMethod · 0.80

Implementers 1

_cogentcore_org_core_plot_plots_Tableyaegicore/symbols/cogentcore_org-core-

Calls 8

LenMethod · 0.95
NewShapeFunction · 0.92
NumDimsMethod · 0.65
IsStringMethod · 0.65
String1DMethod · 0.65
Float1DMethod · 0.65
ShapeMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected