This repository was archived by the owner on Jul 1, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -551,7 +551,7 @@ public final class _ExecutionContext {
551
551
@usableFromInline let eagerContext : CTFEContext
552
552
553
553
/// The status for checking TensorFlow errors.
554
- private let status : CTFStatus = TF_NewStatus ( )
554
+ @ usableFromInline let status : CTFStatus = TF_NewStatus ( )
555
555
556
556
/// The mutex for preventing potential concurrent access.
557
557
private var mutex : pthread_mutex_t = pthread_mutex_t ( )
Original file line number Diff line number Diff line change 12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ import CTensorFlow
16
+
15
17
infix operator .== : ComparisonPrecedence
16
18
infix operator .!= : ComparisonPrecedence
17
19
@@ -50,7 +52,10 @@ public extension Tensor {
50
52
var rank : Int {
51
53
@_semantics ( " autodiff.nonvarying " )
52
54
get {
53
- return Int ( rankTensor. scalar!)
55
+ let status = _ExecutionContext. global. status
56
+ let rank = TFE_TensorHandleNumDims ( handle. _cTensorHandle, status)
57
+ checkOk ( status)
58
+ return Int ( rank)
54
59
}
55
60
}
56
61
@@ -59,15 +64,25 @@ public extension Tensor {
59
64
var shape : TensorShape {
60
65
@_semantics ( " autodiff.nonvarying " )
61
66
get {
62
- return TensorShape ( shapeTensor. scalars. map ( Int . init) )
67
+ let status = _ExecutionContext. global. status
68
+ let dims : [ Int ] = ( 0 ..< Int32 ( rank) ) . map { i in
69
+ let dim = TFE_TensorHandleDim ( self . handle. _cTensorHandle, i, status)
70
+ checkOk ( status)
71
+ return Int ( dim)
72
+ }
73
+ return TensorShape ( dims)
63
74
}
64
75
}
65
76
66
77
/// The number of scalars in the `Tensor`.
67
78
@inlinable
68
79
var scalarCount : Int {
80
+ @_semantics ( " autodiff.nonvarying " )
69
81
get {
70
- return Int ( scalarCountTensor. scalar!)
82
+ let status = _ExecutionContext. global. status
83
+ let size = TFE_TensorHandleNumElements ( handle. _cTensorHandle, status)
84
+ checkOk ( status)
85
+ return Int ( size)
71
86
}
72
87
}
73
88
You can’t perform that action at this time.
0 commit comments