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)
| 13 | // rowEx returns the number of "extra" (higher dimensional) rows |
| 14 | // and colEx returns the number of extra cols |
| 15 | func 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). |