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

Function Projection2DShape

tensor/projection2d.go:15–45  ·  view source on GitHub ↗

Projection2DShape returns the size of a 2D projection of the given tensor Shape, collapsing higher dimensions down to 2D (and 1D up to 2D). For any odd number of dimensions, the remaining outer-most dimension can either be multipliexed across the row or column, given the oddRow arg. Even multiples o

(shp *Shape, oddRow bool)

Source from the content-addressed store, hash-verified

13// rowEx returns the number of "extra" (higher dimensional) rows
14// and colEx returns the number of extra cols
15func Projection2DShape(shp *Shape, oddRow bool) (rows, cols, rowEx, colEx int) {
16 if shp.Len() == 0 {
17 return 1, 1, 0, 0
18 }
19 nd := shp.NumDims()
20 switch nd {
21 case 1:
22 if oddRow {
23 return shp.DimSize(0), 1, 0, 0
24 } else {
25 return 1, shp.DimSize(0), 0, 0
26 }
27 case 2:
28 return shp.DimSize(0), shp.DimSize(1), 0, 0
29 case 3:
30 if oddRow {
31 return shp.DimSize(0) * shp.DimSize(1), shp.DimSize(2), shp.DimSize(0), 0
32 } else {
33 return shp.DimSize(1), shp.DimSize(0) * shp.DimSize(2), 0, shp.DimSize(0)
34 }
35 case 4:
36 return shp.DimSize(0) * shp.DimSize(2), shp.DimSize(1) * shp.DimSize(3), shp.DimSize(0), shp.DimSize(1)
37 case 5:
38 if oddRow {
39 return shp.DimSize(0) * shp.DimSize(1) * shp.DimSize(3), shp.DimSize(2) * shp.DimSize(4), shp.DimSize(0) * shp.DimSize(1), 0
40 } else {
41 return shp.DimSize(1) * shp.DimSize(3), shp.DimSize(0) * shp.DimSize(2) * shp.DimSize(4), 0, shp.DimSize(0) * shp.DimSize(1)
42 }
43 }
44 return 1, 1, 0, 0
45}
46
47// Projection2DIndex returns the flat 1D index for given row, col coords for a 2D projection
48// of the given tensor shape, collapsing higher dimensions down to 2D (and 1D up to 2D).

Callers 7

MinSizeMethod · 0.92
RenderMethod · 0.92
MinSizeMethod · 0.92
RenderMethod · 0.92
StringMethod · 0.85
StringMethod · 0.85
StringMethod · 0.85

Calls 3

LenMethod · 0.65
NumDimsMethod · 0.65
DimSizeMethod · 0.65

Tested by

no test coverage detected