MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Shape

Method Shape

tensorflow/go/operation.go:97–124  ·  view source on GitHub ↗

Shape returns the (possibly incomplete) shape of the tensor produced p.

()

Source from the content-addressed store, hash-verified

95
96// Shape returns the (possibly incomplete) shape of the tensor produced p.
97func (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
126func (p Output) c() C.TF_Output {
127 if p.Op == nil {

Callers

nothing calls this directly

Calls 6

cMethod · 0.95
newStatusFunction · 0.85
makeFunction · 0.85
int64Function · 0.85
ScalarShapeFunction · 0.70
ErrMethod · 0.45

Tested by

no test coverage detected