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 @@ -554,7 +554,7 @@ public final class _ExecutionContext {
554
554
@usableFromInline let eagerContext : CTFEContext
555
555
556
556
/// The status for checking TensorFlow errors.
557
- private let status : CTFStatus = TF_NewStatus ( )
557
+ @ usableFromInline let status : CTFStatus = TF_NewStatus ( )
558
558
559
559
/// The mutex for preventing potential concurrent access.
560
560
private var mutex : pthread_mutex_t = pthread_mutex_t ( )
Original file line number Diff line number Diff line change @@ -367,7 +367,10 @@ public extension Tensor {
367
367
var rank : Int {
368
368
@_semantics ( " autodiff.nonvarying " )
369
369
get {
370
- return Int ( rankTensor. scalar!)
370
+ let status = _ExecutionContext. global. status
371
+ let rank = TFE_TensorHandleNumDims ( handle. _cTensorHandle, status)
372
+ checkOk ( status)
373
+ return Int ( rank)
371
374
}
372
375
}
373
376
@@ -376,14 +379,26 @@ public extension Tensor {
376
379
var shape : TensorShape {
377
380
@_semantics ( " autodiff.nonvarying " )
378
381
get {
379
- return TensorShape ( shapeTensor. scalars. map ( Int . init) )
382
+ let status = _ExecutionContext. global. status
383
+ let dims : [ Int ] = ( 0 ..< Int32 ( rank) ) . map { i in
384
+ let dim = TFE_TensorHandleDim ( self . handle. _cTensorHandle, i, status)
385
+ checkOk ( status)
386
+ return Int ( dim)
387
+ }
388
+ return TensorShape ( dims)
380
389
}
381
390
}
382
391
383
392
/// The number of scalars in the `Tensor`.
384
393
@inlinable
385
394
var scalarCount : Int {
386
- return Int ( scalarCountTensor. scalar!)
395
+ @_semantics ( " autodiff.nonvarying " )
396
+ get {
397
+ let status = _ExecutionContext. global. status
398
+ let size = TFE_TensorHandleNumElements ( handle. _cTensorHandle, status)
399
+ checkOk ( status)
400
+ return Int ( size)
401
+ }
387
402
}
388
403
}
389
404
You can’t perform that action at this time.
0 commit comments