@@ -301,6 +301,50 @@ func.func @test_reduce_mean_dim$basic(%arg0: !torch.vtensor<[3,4,5,6],f32>) -> !
301301
302302// -----
303303
304+ // CHECK-LABEL: func.func @test_reduce_mean_scalar_dim(
305+ // CHECK-SAME: %[[INPUT:.*]]: !torch.vtensor<[],f32>) -> !torch.vtensor<[],f32> {
306+ // CHECK: %[[INPUT_TENSOR:.*]] = torch_c.to_builtin_tensor %[[INPUT]] : !torch.vtensor<[],f32> -> tensor<f32>
307+ // CHECK-NOT: tosa.reduce_sum
308+ // CHECK: %[[IDENTITY:.*]] = tosa.identity %[[INPUT_TENSOR]] : (tensor<f32>) -> tensor<f32>
309+ // CHECK: %[[ONE:.*]] = "tosa.const"() <{values = dense<1.000000e+00> : tensor<f32>}> : () -> tensor<f32>
310+ // CHECK: %[[SCALE:.*]] = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
311+ // CHECK: %[[MUL:.*]] = tosa.mul %[[IDENTITY]], %[[ONE]], %[[SCALE]] : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>
312+ // CHECK: %[[RESULT:.*]] = torch_c.from_builtin_tensor %[[MUL]] : tensor<f32> -> !torch.vtensor<[],f32>
313+ // CHECK: return %[[RESULT]] : !torch.vtensor<[],f32>
314+ // CHECK: }
315+ func.func @test_reduce_mean_scalar_dim (%arg0: !torch.vtensor <[],f32 >) -> !torch.vtensor <[],f32 > {
316+ %dim0 = torch.constant.int 0
317+ %reducedims = torch.prim.ListConstruct %dim0 : (!torch.int ) -> !torch.list <int >
318+ %keepdims = torch.constant.bool false
319+ %dtype = torch.constant.none
320+ %0 = torch.aten.mean.dim %arg0 , %reducedims , %keepdims , %dtype : !torch.vtensor <[],f32 >, !torch.list <int >, !torch.bool , !torch.none -> !torch.vtensor <[],f32 >
321+ return %0 : !torch.vtensor <[],f32 >
322+ }
323+
324+ // -----
325+
326+ // CHECK-LABEL: func.func @test_reduce_mean_scalar_negative_dim(
327+ // CHECK-SAME: %[[INPUT:.*]]: !torch.vtensor<[],f32>) -> !torch.vtensor<[],f32> {
328+ // CHECK: %[[INPUT_TENSOR:.*]] = torch_c.to_builtin_tensor %[[INPUT]] : !torch.vtensor<[],f32> -> tensor<f32>
329+ // CHECK-NOT: tosa.reduce_sum
330+ // CHECK: %[[IDENTITY:.*]] = tosa.identity %[[INPUT_TENSOR]] : (tensor<f32>) -> tensor<f32>
331+ // CHECK: %[[ONE:.*]] = "tosa.const"() <{values = dense<1.000000e+00> : tensor<f32>}> : () -> tensor<f32>
332+ // CHECK: %[[SCALE:.*]] = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
333+ // CHECK: %[[MUL:.*]] = tosa.mul %[[IDENTITY]], %[[ONE]], %[[SCALE]] : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>
334+ // CHECK: %[[RESULT:.*]] = torch_c.from_builtin_tensor %[[MUL]] : tensor<f32> -> !torch.vtensor<[],f32>
335+ // CHECK: return %[[RESULT]] : !torch.vtensor<[],f32>
336+ // CHECK: }
337+ func.func @test_reduce_mean_scalar_negative_dim (%arg0: !torch.vtensor <[],f32 >) -> !torch.vtensor <[],f32 > {
338+ %dim = torch.constant.int -1
339+ %reducedims = torch.prim.ListConstruct %dim : (!torch.int ) -> !torch.list <int >
340+ %keepdims = torch.constant.bool false
341+ %dtype = torch.constant.none
342+ %0 = torch.aten.mean.dim %arg0 , %reducedims , %keepdims , %dtype : !torch.vtensor <[],f32 >, !torch.list <int >, !torch.bool , !torch.none -> !torch.vtensor <[],f32 >
343+ return %0 : !torch.vtensor <[],f32 >
344+ }
345+
346+ // -----
347+
304348// CHECK-LABEL: func.func @test_reduce_sum_dims$basic(
305349// CHECK-SAME: %[[VAL_0:.*]]: !torch.vtensor<[3,4,5,6],f32>) -> !torch.vtensor<[4,5,6],f32> {
306350// CHECK: %[[VAL_1:.*]] = torch_c.to_builtin_tensor %[[VAL_0]] : !torch.vtensor<[3,4,5,6],f32> -> tensor<3x4x5x6xf32>
@@ -325,6 +369,44 @@ func.func @test_reduce_sum_dims$basic(%arg0: !torch.vtensor<[3,4,5,6],f32>) -> !
325369
326370// -----
327371
372+ // CHECK-LABEL: func.func @test_reduce_sum_scalar_dim$basic(
373+ // CHECK-SAME: %[[INPUT:.*]]: !torch.vtensor<[],f32>) -> !torch.vtensor<[],f32> {
374+ // CHECK: %[[INPUT_TENSOR:.*]] = torch_c.to_builtin_tensor %[[INPUT]] : !torch.vtensor<[],f32> -> tensor<f32>
375+ // CHECK-NOT: tosa.reduce_sum
376+ // CHECK: %[[IDENTITY:.*]] = tosa.identity %[[INPUT_TENSOR]] : (tensor<f32>) -> tensor<f32>
377+ // CHECK: %[[RESULT:.*]] = torch_c.from_builtin_tensor %[[IDENTITY]] : tensor<f32> -> !torch.vtensor<[],f32>
378+ // CHECK: return %[[RESULT]] : !torch.vtensor<[],f32>
379+ // CHECK: }
380+ func.func @test_reduce_sum_scalar_dim$basic (%arg0: !torch.vtensor <[],f32 >) -> !torch.vtensor <[],f32 > {
381+ %none = torch.constant.none
382+ %false = torch.constant.bool false
383+ %int0 = torch.constant.int 0
384+ %dims = torch.prim.ListConstruct %int0 : (!torch.int ) -> !torch.list <int >
385+ %0 = torch.aten.sum.dim_IntList %arg0 , %dims , %false , %none : !torch.vtensor <[],f32 >, !torch.list <int >, !torch.bool , !torch.none -> !torch.vtensor <[],f32 >
386+ return %0 : !torch.vtensor <[],f32 >
387+ }
388+
389+ // -----
390+
391+ // CHECK-LABEL: func.func @test_reduce_sum_scalar_negative_dim$basic(
392+ // CHECK-SAME: %[[INPUT:.*]]: !torch.vtensor<[],f32>) -> !torch.vtensor<[],f32> {
393+ // CHECK: %[[INPUT_TENSOR:.*]] = torch_c.to_builtin_tensor %[[INPUT]] : !torch.vtensor<[],f32> -> tensor<f32>
394+ // CHECK-NOT: tosa.reduce_sum
395+ // CHECK: %[[IDENTITY:.*]] = tosa.identity %[[INPUT_TENSOR]] : (tensor<f32>) -> tensor<f32>
396+ // CHECK: %[[RESULT:.*]] = torch_c.from_builtin_tensor %[[IDENTITY]] : tensor<f32> -> !torch.vtensor<[],f32>
397+ // CHECK: return %[[RESULT]] : !torch.vtensor<[],f32>
398+ // CHECK: }
399+ func.func @test_reduce_sum_scalar_negative_dim$basic (%arg0: !torch.vtensor <[],f32 >) -> !torch.vtensor <[],f32 > {
400+ %none = torch.constant.none
401+ %false = torch.constant.bool false
402+ %int -1 = torch.constant.int -1
403+ %dims = torch.prim.ListConstruct %int -1 : (!torch.int ) -> !torch.list <int >
404+ %0 = torch.aten.sum.dim_IntList %arg0 , %dims , %false , %none : !torch.vtensor <[],f32 >, !torch.list <int >, !torch.bool , !torch.none -> !torch.vtensor <[],f32 >
405+ return %0 : !torch.vtensor <[],f32 >
406+ }
407+
408+ // -----
409+
328410// CHECK-LABEL: func.func @test_reduce_sum_empty_dims$basic(
329411// CHECK-SAME: %[[INPUT_F32:.*]]: !torch.vtensor<[2,3,4],f32>) -> !torch.vtensor<[],f32> {
330412// CHECK: %[[INPUT_F32_TENSOR:.*]] = torch_c.to_builtin_tensor %[[INPUT_F32]] : !torch.vtensor<[2,3,4],f32> -> tensor<2x3x4xf32>
@@ -405,6 +487,56 @@ func.func @test_linalg_vector_norm$basic(%arg0: !torch.vtensor<[3,151,64],f32>)
405487
406488// -----
407489
490+ // CHECK-LABEL: func.func @test_linalg_vector_norm_scalar_dim(
491+ // CHECK-SAME: %[[INPUT:.*]]: !torch.vtensor<[],f32>) -> !torch.vtensor<[],f32> {
492+ // CHECK: %[[INPUT_TENSOR:.*]] = torch_c.to_builtin_tensor %[[INPUT]] : !torch.vtensor<[],f32> -> tensor<f32>
493+ // CHECK: %[[ORD:.*]] = "tosa.const"() <{values = dense<3.000000e+00> : tensor<f32>}> : () -> tensor<f32>
494+ // CHECK: %[[ABS:.*]] = tosa.abs %[[INPUT_TENSOR]] : (tensor<f32>) -> tensor<f32>
495+ // CHECK: %[[POW:.*]] = tosa.pow %[[ABS]], %[[ORD]] : (tensor<f32>, tensor<f32>) -> tensor<f32>
496+ // CHECK-NOT: tosa.reduce_sum
497+ // CHECK: %[[IDENTITY:.*]] = tosa.identity %[[POW]] : (tensor<f32>) -> tensor<f32>
498+ // CHECK: %[[RECIPROCAL:.*]] = tosa.reciprocal %[[ORD]] : (tensor<f32>) -> tensor<f32>
499+ // CHECK: %[[RESULT_TENSOR:.*]] = tosa.pow %[[IDENTITY]], %[[RECIPROCAL]] : (tensor<f32>, tensor<f32>) -> tensor<f32>
500+ // CHECK: %[[RESULT:.*]] = torch_c.from_builtin_tensor %[[RESULT_TENSOR]] : tensor<f32> -> !torch.vtensor<[],f32>
501+ // CHECK: return %[[RESULT]] : !torch.vtensor<[],f32>
502+ // CHECK: }
503+ func.func @test_linalg_vector_norm_scalar_dim (%arg0: !torch.vtensor <[],f32 >) -> !torch.vtensor <[],f32 > {
504+ %ord = torch.constant.float 3.000000e+00
505+ %dim = torch.constant.int 0
506+ %keepdims = torch.constant.bool false
507+ %dtype = torch.constant.none
508+ %dims = torch.prim.ListConstruct %dim : (!torch.int ) -> !torch.list <int >
509+ %0 = torch.aten.linalg_vector_norm %arg0 , %ord , %dims , %keepdims , %dtype : !torch.vtensor <[],f32 >, !torch.float , !torch.list <int >, !torch.bool , !torch.none -> !torch.vtensor <[],f32 >
510+ return %0 : !torch.vtensor <[],f32 >
511+ }
512+
513+ // -----
514+
515+ // CHECK-LABEL: func.func @test_linalg_vector_norm_scalar_negative_dim(
516+ // CHECK-SAME: %[[INPUT:.*]]: !torch.vtensor<[],f32>) -> !torch.vtensor<[],f32> {
517+ // CHECK: %[[INPUT_TENSOR:.*]] = torch_c.to_builtin_tensor %[[INPUT]] : !torch.vtensor<[],f32> -> tensor<f32>
518+ // CHECK: %[[ORD:.*]] = "tosa.const"() <{values = dense<3.000000e+00> : tensor<f32>}> : () -> tensor<f32>
519+ // CHECK: %[[ABS:.*]] = tosa.abs %[[INPUT_TENSOR]] : (tensor<f32>) -> tensor<f32>
520+ // CHECK: %[[POW:.*]] = tosa.pow %[[ABS]], %[[ORD]] : (tensor<f32>, tensor<f32>) -> tensor<f32>
521+ // CHECK-NOT: tosa.reduce_sum
522+ // CHECK: %[[IDENTITY:.*]] = tosa.identity %[[POW]] : (tensor<f32>) -> tensor<f32>
523+ // CHECK: %[[RECIPROCAL:.*]] = tosa.reciprocal %[[ORD]] : (tensor<f32>) -> tensor<f32>
524+ // CHECK: %[[RESULT_TENSOR:.*]] = tosa.pow %[[IDENTITY]], %[[RECIPROCAL]] : (tensor<f32>, tensor<f32>) -> tensor<f32>
525+ // CHECK: %[[RESULT:.*]] = torch_c.from_builtin_tensor %[[RESULT_TENSOR]] : tensor<f32> -> !torch.vtensor<[],f32>
526+ // CHECK: return %[[RESULT]] : !torch.vtensor<[],f32>
527+ // CHECK: }
528+ func.func @test_linalg_vector_norm_scalar_negative_dim (%arg0: !torch.vtensor <[],f32 >) -> !torch.vtensor <[],f32 > {
529+ %ord = torch.constant.float 3.000000e+00
530+ %dim = torch.constant.int -1
531+ %keepdims = torch.constant.bool false
532+ %dtype = torch.constant.none
533+ %dims = torch.prim.ListConstruct %dim : (!torch.int ) -> !torch.list <int >
534+ %0 = torch.aten.linalg_vector_norm %arg0 , %ord , %dims , %keepdims , %dtype : !torch.vtensor <[],f32 >, !torch.float , !torch.list <int >, !torch.bool , !torch.none -> !torch.vtensor <[],f32 >
535+ return %0 : !torch.vtensor <[],f32 >
536+ }
537+
538+ // -----
539+
408540// CHECK-LABEL: func.func @test_reduce_sum$basic(
409541// CHECK-SAME: %[[VAL_0:.*]]: !torch.vtensor<[?,?,?,?],f32>) -> !torch.vtensor<[1],f32> {
410542// CHECK: %[[VAL_1:.*]] = torch_c.to_builtin_tensor %[[VAL_0]] : !torch.vtensor<[?,?,?,?],f32> -> tensor<?x?x?x?xf32>
0 commit comments