@@ -1291,8 +1291,48 @@ def reciprocal(x):
1291
1291
1292
1292
1293
1293
def repeat (x , repeats , axis = None ):
1294
- raise NotImplementedError ("`repeat` is not supported with openvino backend" )
1294
+ x = get_ov_output (x )
1295
+
1296
+ if axis is not None and axis < 0 :
1297
+ axis += len (x .get_partial_shape ())
1295
1298
1299
+ if axis is None :
1300
+ x = ov_opset .reshape (x , ov_opset .constant ([- 1 ], Type .i32 ), special_zero = False ).output (0 )
1301
+ axis = 0
1302
+
1303
+ if isinstance (repeats , (int , np .integer )) or (
1304
+ isinstance (repeats , np .ndarray ) and repeats .ndim == 1 and repeats .size == 1
1305
+ ):
1306
+ repeats_val = int (repeats ) if isinstance (repeats , np .ndarray ) else repeats
1307
+ input_shape = ov_opset .shape_of (x , Type .i32 ).output (0 )
1308
+ dim_len = ov_opset .gather (input_shape , ov_opset .constant ([axis ], Type .i32 ), ov_opset .constant (0 , Type .i32 )).output (0 )
1309
+ dim_len = ov_opset .squeeze (dim_len , ov_opset .constant ([0 ], Type .i32 )).output (0 )
1310
+ idx_range = ov_opset .range (
1311
+ ov_opset .constant (0 , Type .i32 ),
1312
+ dim_len ,
1313
+ ov_opset .constant (1 , Type .i32 ),
1314
+ output_type = Type .i32 ,
1315
+ ).output (0 )
1316
+ idx_range = ov_opset .unsqueeze (idx_range , ov_opset .constant ([1 ], Type .i32 )).output (0 )
1317
+ tiled = ov_opset .tile (idx_range , ov_opset .constant ([1 , repeats_val ], Type .i32 )).output (0 )
1318
+ idx = ov_opset .reshape (tiled , ov_opset .constant ([- 1 ], Type .i32 ), special_zero = False ).output (0 )
1319
+ result = ov_opset .gather (x , idx , ov_opset .constant (axis , Type .i32 )).output (0 )
1320
+ return OpenVINOKerasTensor (result )
1321
+
1322
+ repeats_np = np .array (repeats )
1323
+ if repeats_np .ndim != 1 :
1324
+ raise NotImplementedError ("Only 1D repeats arrays are supported." )
1325
+ input_shape = ov_opset .shape_of (x , Type .i32 ).output (0 )
1326
+ axis_len = ov_opset .gather (input_shape , ov_opset .constant ([axis ], Type .i32 ), ov_opset .constant (0 , Type .i32 )).output (0 )
1327
+ axis_len_val = int (axis_len .get_vector ()[0 ]) if hasattr (axis_len , "get_vector" ) else x .get_partial_shape ()[axis ]
1328
+ if axis_len_val != len (repeats_np ):
1329
+ raise ValueError ("repeats length does not match axis length" )
1330
+
1331
+ gather_indices = np .concatenate ([np .full (r , i , dtype = np .int32 ) for i , r in enumerate (repeats_np ) if r > 0 ])
1332
+ gather_indices_ov = ov_opset .constant (gather_indices , Type .i32 ).output (0 )
1333
+ result = ov_opset .gather (x , gather_indices_ov , ov_opset .constant (axis , Type .i32 )).output (0 )
1334
+ return OpenVINOKerasTensor (result )
1335
+
1296
1336
1297
1337
def reshape (x , newshape ):
1298
1338
x = get_ov_output (x )
0 commit comments