TableHeaders generates special header strings from the table with full information about type and tensor cell dimensionality.
()
| 527 | // TableHeaders generates special header strings from the table |
| 528 | // with full information about type and tensor cell dimensionality. |
| 529 | func (dt *Table) TableHeaders() []string { |
| 530 | hdrs := []string{} |
| 531 | for i := range dt.Columns { |
| 532 | tsr := dt.Columns[i] |
| 533 | nm := dt.ColumnNames[i] |
| 534 | nm = string([]byte{TableHeaderChar(tsr.DataType())}) + nm |
| 535 | if tsr.NumDims() == 1 { |
| 536 | hdrs = append(hdrs, nm) |
| 537 | } else { |
| 538 | csh := tensor.NewShape(tsr.Shape().Sizes[1:]) // cell shape |
| 539 | tc := csh.Len() |
| 540 | nd := csh.NumDims() |
| 541 | fnm := nm + fmt.Sprintf("[%v:", nd) |
| 542 | dn := fmt.Sprintf("<%v:", nd) |
| 543 | ffnm := fnm |
| 544 | for di := 0; di < nd; di++ { |
| 545 | ffnm += "0" |
| 546 | dn += fmt.Sprintf("%v", csh.DimSize(di)) |
| 547 | if di < nd-1 { |
| 548 | ffnm += "," |
| 549 | dn += "," |
| 550 | } |
| 551 | } |
| 552 | ffnm += "]" + dn + ">" |
| 553 | hdrs = append(hdrs, ffnm) |
| 554 | for ti := 1; ti < tc; ti++ { |
| 555 | idx := csh.Index(ti) |
| 556 | ffnm := fnm |
| 557 | for di := 0; di < nd; di++ { |
| 558 | ffnm += fmt.Sprintf("%v", idx[di]) |
| 559 | if di < nd-1 { |
| 560 | ffnm += "," |
| 561 | } |
| 562 | } |
| 563 | ffnm += "]" |
| 564 | hdrs = append(hdrs, ffnm) |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | return hdrs |
| 569 | } |