Shape returns the (possibly incomplete) shape of the tensor produced p.
()
| 95 | |
| 96 | // Shape returns the (possibly incomplete) shape of the tensor produced p. |
| 97 | func (p Output) Shape() Shape { |
| 98 | status := newStatus() |
| 99 | port := p.c() |
| 100 | ndims := C.TF_GraphGetTensorNumDims(p.Op.g.c, port, status.c) |
| 101 | if err := status.Err(); err != nil { |
| 102 | // This should not be possible since an error only occurs if |
| 103 | // the operation does not belong to the graph. It should not |
| 104 | // be possible to construct such an Operation object. |
| 105 | return Shape{} |
| 106 | } |
| 107 | if ndims < 0 { |
| 108 | return Shape{} |
| 109 | } |
| 110 | if ndims == 0 { |
| 111 | return ScalarShape() |
| 112 | } |
| 113 | dims := make([]C.int64_t, ndims) |
| 114 | C.TF_GraphGetTensorShape(p.Op.g.c, port, &dims[0], ndims, status.c) |
| 115 | if err := status.Err(); err != nil { |
| 116 | // Same as above, should not be possible. |
| 117 | return Shape{} |
| 118 | } |
| 119 | ret := Shape{dims: make([]int64, ndims)} |
| 120 | for i := 0; i < int(ndims); i++ { |
| 121 | ret.dims[i] = int64(dims[i]) |
| 122 | } |
| 123 | return ret |
| 124 | } |
| 125 | |
| 126 | func (p Output) c() C.TF_Output { |
| 127 | if p.Op == nil { |