@@ -132,18 +132,18 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
132
132
override t.GetItem ( indexes : int []) =
133
133
Shape.checkCanIndex t.Shape indexes
134
134
if t.Shape.Length = 0 then t.ToScalar()
135
- else t.MakeLike( tt= tt. [ indexes |> Array.map ( fun v -> torch.TensorIndex.Single( int64 v))], shape=[||]) .ToScalar()
135
+ else t.MakeLike( tt= tt[ indexes |> Array.map ( fun v -> torch.TensorIndex.Single( int64 v))], shape=[||]) .ToScalar()
136
136
137
137
override t.GetSlice ( fullBounds : int [,]) =
138
138
let n = fullBounds.GetLength( 0 )
139
139
let newShape = Shape.checkCanGetSlice t.Shape fullBounds
140
140
141
141
let indices =
142
142
Array.init n ( fun i ->
143
- let start = fullBounds. [ i, 0 ]
144
- let stop = fullBounds. [ i, 1 ] + 1
143
+ let start = fullBounds[ i, 0 ]
144
+ let stop = fullBounds[ i, 1 ] + 1
145
145
let len = stop - start
146
- if fullBounds. [ i, 2 ] = 1 && len = 1 then
146
+ if fullBounds[ i, 2 ] = 1 && len = 1 then
147
147
torch.TensorIndex.Single( int64 start)
148
148
else
149
149
torch.TensorIndex.Slice( start= int64 start, stop= int64 stop))
@@ -164,27 +164,27 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
164
164
| Dtype.Int8 ->
165
165
let data = tt.data< sbyte>()
166
166
for i in 0 .. n-1 do
167
- res <- combineHashes res ( int32 data. [ int64 i])
167
+ res <- combineHashes res ( int32 data[ int64 i])
168
168
| Dtype.Byte ->
169
169
let data = tt.data< byte>()
170
170
for i in 0 .. n-1 do
171
- res <- combineHashes res ( int32 data. [ int64 i])
171
+ res <- combineHashes res ( int32 data[ int64 i])
172
172
| Dtype.Bool ->
173
173
let data = tt.data< byte>()
174
174
for i in 0 .. n-1 do
175
- res <- combineHashes res ( int32 data. [ int64 i])
175
+ res <- combineHashes res ( int32 data[ int64 i])
176
176
| Dtype.Int16 ->
177
177
let data = tt.data< int16>()
178
178
for i in 0 .. n-1 do
179
- res <- combineHashes res ( int32 data. [ int64 i] )
179
+ res <- combineHashes res ( int32 data[ int64 i] )
180
180
| Dtype.Int32 ->
181
181
let data = tt.data< int32>()
182
182
for i in 0 .. n-1 do
183
- res <- combineHashes res ( int32 data. [ int64 i])
183
+ res <- combineHashes res ( int32 data[ int64 i])
184
184
| Dtype.Int64 ->
185
185
let data = tt.data< int64>()
186
186
for i in 0 .. n-1 do
187
- res <- combineHashes res ( int32 data. [ int64 i])
187
+ res <- combineHashes res ( int32 data[ int64 i])
188
188
| Dtype.Float16 ->
189
189
for i in 0 .. n-1 do
190
190
res <- combineHashes res ( hash ( tt.ReadCpuFloat16( int64 i)))
@@ -194,11 +194,11 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
194
194
| Dtype.Float32 ->
195
195
let data = tt.data< single>()
196
196
for i in 0 .. n-1 do
197
- res <- combineHashes res ( hash data. [ int64 i])
197
+ res <- combineHashes res ( hash data[ int64 i])
198
198
| Dtype.Float64 ->
199
199
let data = tt.data< double>()
200
200
for i in 0 .. n-1 do
201
- res <- combineHashes res ( hash data. [ int64 i])
201
+ res <- combineHashes res ( hash data[ int64 i])
202
202
res
203
203
204
204
override t.Expand ( newShape ) =
@@ -222,12 +222,12 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
222
222
let tt = torchMoveTo tt Device.CPU
223
223
match t.Shape with
224
224
| [| |] -> tt.ToScalar() |> box
225
- | [| d0 |] -> upcast Array.init< 'T> d0 ( fun i -> tt. [ int64 i] |> conv)
226
- | [| d0; d1 |] -> upcast Array2D.init< 'T> d0 d1 ( fun i j -> tt. [ int64 i, int64 j] |> conv)
227
- | [| d0; d1; d2 |] -> upcast Array3D.init< 'T> d0 d1 d2 ( fun i j k -> tt. [ int64 i, int64 j, int64 k] |> conv)
228
- | [| d0; d1; d2; d3 |] -> upcast Array4D.init< 'T> d0 d1 d2 d3 ( fun i j k l -> tt. [ int64 i, int64 j, int64 k, int64 l] |> conv)
229
- | [| d0; d1; d2; d3; d4 |] -> upcast Array5D.init< 'T> d0 d1 d2 d3 d4 ( fun i j k l m -> tt. [ int64 i, int64 j, int64 k, int64 l, int64 m] |> conv)
230
- | [| d0; d1; d2; d3; d4; d5 |] -> upcast Array6D.init< 'T> d0 d1 d2 d3 d4 d5 ( fun i j k l m n -> tt. [ int64 i, int64 j, int64 k, int64 l, int64 m, int64 n] |> conv)
225
+ | [| d0 |] -> upcast Array.init< 'T> d0 ( fun i -> tt[ int64 i] |> conv)
226
+ | [| d0; d1 |] -> upcast Array2D.init< 'T> d0 d1 ( fun i j -> tt[ int64 i, int64 j] |> conv)
227
+ | [| d0; d1; d2 |] -> upcast Array3D.init< 'T> d0 d1 d2 ( fun i j k -> tt[ int64 i, int64 j, int64 k] |> conv)
228
+ | [| d0; d1; d2; d3 |] -> upcast Array4D.init< 'T> d0 d1 d2 d3 ( fun i j k l -> tt[ int64 i, int64 j, int64 k, int64 l] |> conv)
229
+ | [| d0; d1; d2; d3; d4 |] -> upcast Array5D.init< 'T> d0 d1 d2 d3 d4 ( fun i j k l m -> tt[ int64 i, int64 j, int64 k, int64 l, int64 m] |> conv)
230
+ | [| d0; d1; d2; d3; d4; d5 |] -> upcast Array6D.init< 'T> d0 d1 d2 d3 d4 d5 ( fun i j k l m n -> tt[ int64 i, int64 j, int64 k, int64 l, int64 m, int64 n] |> conv)
231
231
| _ -> failwithf " Cannot get array for Tensor dimensions > 6. Consider slicing the Tensor. Shape: %A " t.Shape
232
232
233
233
override t.ToValues () =
@@ -250,7 +250,7 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
250
250
let data = tt2.data< 'T>()
251
251
let res = Array.zeroCreate< 'T> ( int32 tt2.NumberOfElements)
252
252
for i in 0 .. int32 tt2.NumberOfElements - 1 do
253
- res. [ i] <- data. [ int64 i]
253
+ res[ i] <- data[ int64 i]
254
254
res
255
255
256
256
member t.ToRawData () : Array =
@@ -276,7 +276,7 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
276
276
let tts , shapes = tensors |> Array.map ( fun t -> ( t :?> TorchRawTensor) .TorchTensor, t.Shape) |> Array.unzip
277
277
let _n , _shape1 , _shape2 , newShape = Shape.checkCanStack shapes dim
278
278
let result = torch.stack( tts, int64 dim)
279
- ( tensors. [0 ] :?> TorchRawTensor) .MakeLike( result, newShape)
279
+ ( tensors[ 0 ] :?> TorchRawTensor) .MakeLike( result, newShape)
280
280
281
281
override t.UnstackT ( dim ) =
282
282
let shape = t.Shape
@@ -336,7 +336,7 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
336
336
let mutable res = tt
337
337
let mutable c = 0
338
338
for i in 0 .. t.Dim - 1 do
339
- if shape. [ i] = 1 && ( dim = - 1 || i = dim) then
339
+ if shape[ i] = 1 && ( dim = - 1 || i = dim) then
340
340
res <- res.squeeze( int64 c)
341
341
else
342
342
c <- c + 1
@@ -364,10 +364,10 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
364
364
let mutable res = tt
365
365
for i= 0 to dims-1 do
366
366
let s = res.shape
367
- s. [ i] <- int64 outputShape. [ i]
367
+ s[ i] <- int64 outputShape[ i]
368
368
let resnew = t.ZerosLike( fromTorchShape s)
369
- let indices = Array.init t.Shape. [ i] id |> Array.map ((*) dilations. [ i] >> int64)
370
- let mutable d = TorchInt64TensorOps() .CreateFromFlatArray( indices, shape=[| t.Shape. [ i]|], device= t.Device)
369
+ let indices = Array.init t.Shape[ i] id |> Array.map ((*) dilations[ i] >> int64)
370
+ let mutable d = TorchInt64TensorOps() .CreateFromFlatArray( indices, shape=[| t.Shape[ i]|], device= t.Device)
371
371
for _= 0 to i-1 do
372
372
d <- d.UnsqueezeT( 0 )
373
373
for _= i+ 1 to dims-1 do
@@ -381,7 +381,7 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
381
381
let outputShape = Shape.undilatedShape shape dilations
382
382
let mutable res = tt
383
383
for d in 0 .. dilations.Length - 1 do
384
- res <- res.slice( int64 d, 0 L, int64 shape. [ d], int64 dilations. [ d])
384
+ res <- res.slice( int64 d, 0 L, int64 shape[ d], int64 dilations[ d])
385
385
t.MakeLike( res, outputShape)
386
386
387
387
override t.GatherT ( dim : int , indices ) =
@@ -497,20 +497,20 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
497
497
for i = t.Dim - 1 downto 0 do
498
498
let ( struct ( values2 , indexes )) = values.max( int64 i)
499
499
values <- values2
500
- idxs. [ i] <- indexes
500
+ idxs[ i] <- indexes
501
501
502
502
for i = 0 to t.Dim - 1 do
503
- let idx = idxs. [ i]
503
+ let idx = idxs[ i]
504
504
505
- res. [ i] <-
505
+ res[ i] <-
506
506
match i with
507
507
| 0 -> idx.ToInt64()
508
- | 1 -> idx. [ res. [0 ]]. ToInt64()
509
- | 2 -> idx. [ res. [0 ], res. [1 ]]. ToInt64()
510
- | 3 -> idx. [ res. [0 ], res. [1 ], res. [2 ]]. ToInt64()
511
- | 4 -> idx. [ res. [0 ], res. [1 ], res. [2 ], res. [3 ]]. ToInt64()
512
- | 5 -> idx. [ res. [0 ], res. [1 ], res. [2 ], res. [3 ], res. [4 ]]. ToInt64()
513
- | 6 -> idx. [ res. [0 ], res. [1 ], res. [2 ], res. [3 ], res. [4 ], res. [5 ]]. ToInt64()
508
+ | 1 -> idx[ res[ 0 ]]. ToInt64()
509
+ | 2 -> idx[ res[ 0 ], res[ 1 ]]. ToInt64()
510
+ | 3 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ]]. ToInt64()
511
+ | 4 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ], res[ 3 ]]. ToInt64()
512
+ | 5 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ], res[ 3 ], res[ 4 ]]. ToInt64()
513
+ | 6 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ], res[ 3 ], res[ 4 ], res[ 5 ]]. ToInt64()
514
514
| _ -> failwith " MaxIndexT > 6d nyi for torch"
515
515
res |> Array.map int32
516
516
@@ -535,20 +535,20 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
535
535
for i = t.Dim - 1 downto 0 do
536
536
let ( struct ( values2 , indexes )) = values.min( int64 i)
537
537
values <- values2
538
- idxs. [ i] <- indexes
538
+ idxs[ i] <- indexes
539
539
540
540
for i = 0 to t.Dim - 1 do
541
- let idx = idxs. [ i]
541
+ let idx = idxs[ i]
542
542
543
- res. [ i] <-
543
+ res[ i] <-
544
544
match i with
545
545
| 0 -> idx.ToInt64()
546
- | 1 -> idx. [ res. [0 ]]. ToInt64()
547
- | 2 -> idx. [ res. [0 ], res. [1 ]]. ToInt64()
548
- | 3 -> idx. [ res. [0 ], res. [1 ], res. [2 ]]. ToInt64()
549
- | 4 -> idx. [ res. [0 ], res. [1 ], res. [2 ], res. [3 ]]. ToInt64()
550
- | 5 -> idx. [ res. [0 ], res. [1 ], res. [2 ], res. [3 ], res. [4 ]]. ToInt64()
551
- | 6 -> idx. [ res. [0 ], res. [1 ], res. [2 ], res. [3 ], res. [4 ], res. [5 ]]. ToInt64()
546
+ | 1 -> idx[ res[ 0 ]]. ToInt64()
547
+ | 2 -> idx[ res[ 0 ], res[ 1 ]]. ToInt64()
548
+ | 3 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ]]. ToInt64()
549
+ | 4 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ], res[ 3 ]]. ToInt64()
550
+ | 5 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ], res[ 3 ], res[ 4 ]]. ToInt64()
551
+ | 6 -> idx[ res[ 0 ], res[ 1 ], res[ 2 ], res[ 3 ], res[ 4 ], res[ 5 ]]. ToInt64()
552
552
| _ -> failwith " MinIndexT > 6d nyi for torch"
553
553
res |> Array.map int32
554
554
@@ -575,9 +575,9 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
575
575
let res = tt.clone()
576
576
let mutable t1Slice = res // will share memory with res
577
577
for d in 0 .. location.Length - 1 do
578
- let len2 = expandedShape2. [ d]
579
- if location. [ d] <> 0 || len2 <> shape1. [ d] then
580
- t1Slice <- t1Slice.narrow( int64 d, int64 location. [ d], int64 len2)
578
+ let len2 = expandedShape2[ d]
579
+ if location[ d] <> 0 || len2 <> shape1[ d] then
580
+ t1Slice <- t1Slice.narrow( int64 d, int64 location[ d], int64 len2)
581
581
t1Slice.add_( t2Expanded) |> ignore
582
582
t1.MakeLike( res)
583
583
@@ -674,8 +674,8 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
674
674
| _ ->
675
675
let ( t1BatchPart , t1MatrixPart ), ( t2BatchPart , t2MatrixPart ) = Shape.checkCanMatmul t1.Shape t2.Shape
676
676
if t1BatchPart <> t2BatchPart then failwithf " Cannot matrix multiply raw tensors with shapes %A , %A - mismatch batching" t1.Shape t2.Shape
677
- let t1rows = t1MatrixPart. [0 ]
678
- let t2cols = t2MatrixPart. [1 ]
677
+ let t1rows = t1MatrixPart[ 0 ]
678
+ let t2cols = t2MatrixPart[ 1 ]
679
679
let newShape = Array.append t1BatchPart [| t1rows; t2cols |]
680
680
let result =
681
681
// "addmm for CUDA tensors only supports floating-point types. Try converting the tensors with .float()" | const char *
@@ -777,7 +777,7 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
777
777
//let batchSize, channels, _inputSize, _outputShape = Shape.computeMaxUnpool1d t1.Shape outputSize
778
778
let t1X = t1.UnsqueezeT( 2 )
779
779
let indicesX = indices.UnsqueezeT( 2 )
780
- let resulttX = t1X.MaxUnpool2D( indicesX, [| outputSize. [0 ]; outputSize. [1 ]; 1 ; outputSize. [2 ] |])
780
+ let resulttX = t1X.MaxUnpool2D( indicesX, [| outputSize[ 0 ]; outputSize[ 1 ]; 1 ; outputSize[ 2 ] |])
781
781
let resultt = resulttX.SqueezeT( 2 )
782
782
resultt
783
783
@@ -789,7 +789,7 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
789
789
790
790
// note, LibTorch only wants the last two elements of the output size passsed in
791
791
// "There should be exactly two elements (height, width) in output_size (max_unpooling2d_shape_check at ...)"
792
- let outputSize = outputSize. [2 .. 3 ]
792
+ let outputSize = outputSize[ 2 .. 3 ]
793
793
794
794
// TODO: consider switching to the torch::nn module for MaxUnpool2d
795
795
@@ -804,7 +804,7 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
804
804
805
805
// note, LibTorch only wants the last three elements of the output size passsed in
806
806
// "There should be exactly three elements (depth, height, width) in output_size (max_unpooling3d_shape_check at ..\..\aten\src\ATen\native\MaxUnpooling.cpp:231)"
807
- let outputSize = outputSize. [2 .. 4 ]
807
+ let outputSize = outputSize[ 2 .. 4 ]
808
808
809
809
// NOTE: strides and padding must always be specified for torch::max_unpool3d C++ entry
810
810
// TODO: consider switching to the torch::nn module for MaxUnpool
@@ -1124,9 +1124,9 @@ type TorchRawTensor(tt: torch.Tensor, shape: Shape, dtype: Dtype, device: Device
1124
1124
let t2Expanded = t2.TorchTensor.expand( toTorchShape expandedShape2)
1125
1125
let mutable t1Slice = tt // will share memory with res
1126
1126
for d in 0 .. location.Length - 1 do
1127
- let len2 = expandedShape2. [ d]
1128
- if location. [ d] <> 0 || len2 <> shape1. [ d] then
1129
- t1Slice <- t1Slice.narrow( int64 d, int64 location. [ d], int64 len2)
1127
+ let len2 = expandedShape2[ d]
1128
+ if location[ d] <> 0 || len2 <> shape1[ d] then
1129
+ t1Slice <- t1Slice.narrow( int64 d, int64 location[ d], int64 len2)
1130
1130
t1Slice.add_( t2Expanded) |> ignore
1131
1131
1132
1132
override _.SubInPlace ( t2 ) = checkMutable(); tt.sub_( t2.TorchTensor) |> ignore
@@ -1246,7 +1246,7 @@ type TorchTensorOps<'T, 'T2>
1246
1246
// torch.InitializeDevice(device.ToTorch) |> ignore
1247
1247
let t =
1248
1248
match shape with
1249
- | [| |] -> fromScalar( values. [0 ])
1249
+ | [| |] -> fromScalar( values[ 0 ])
1250
1250
| _ -> from ( values, toTorchShape shape)
1251
1251
let tt = torchMoveTo t device
1252
1252
TorchRawTensor( tt, shape, dtype, device) :> RawTensor
@@ -1419,14 +1419,14 @@ type TorchBackendTensorStatics() =
1419
1419
let supported = Array.zeroCreate< int> 32
1420
1420
let isSupported ( deviceType : DiffSharp.DeviceType ) =
1421
1421
let n = int deviceType
1422
- match supported. [ n] with
1422
+ match supported[ n] with
1423
1423
| 0 ->
1424
1424
try
1425
1425
torch.empty([| 1 L |], device= torch.Device( deviceType.ToTorch, index= 0 )) |> ignore
1426
- supported. [ n] <- 1
1426
+ supported[ n] <- 1
1427
1427
true
1428
1428
with _ ->
1429
- supported. [ n] <- 2
1429
+ supported[ n] <- 2
1430
1430
false
1431
1431
| 1 -> true
1432
1432
| _ -> false
0 commit comments