@@ -919,109 +919,58 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis
919
919
if dtype is None :
920
920
ov_dtype = OPENVINO_DTYPES [config .floatx ()]
921
921
else :
922
- ov_dtype = OPENVINO_DTYPES [dtype ]
922
+ try :
923
+ ov_dtype = OPENVINO_DTYPES [dtype ]
924
+ except KeyError :
925
+ ov_dtype = OPENVINO_DTYPES ["float32" ]
923
926
924
927
start_ov = ov_opset .convert (start_ov , ov_dtype ).output (0 )
925
928
stop_ov = ov_opset .convert (stop_ov , ov_dtype ).output (0 )
926
929
927
- start_shape = start_ov .get_shape ()
928
- stop_shape = stop_ov .get_shape ()
929
-
930
930
if num == 0 :
931
- if len (start_shape ) == 0 and len (stop_shape ) == 0 :
932
- result = ov_opset .constant (np .array ([], dtype = np .dtype (dtype or config .floatx ()))).output (0 )
933
- else :
934
- out_shape = list (np .broadcast (
935
- np .empty (start_shape , dtype = bool ),
936
- np .empty (stop_shape , dtype = bool )
937
- ).shape )
938
- out_shape .insert (axis , 0 )
939
-
940
- empty_np = np .empty (out_shape , dtype = np .dtype (dtype or config .floatx ()))
941
- empty_np = np .reshape (empty_np , [- 1 ])
942
- result = ov_opset .constant (empty_np ).output (0 )
943
-
944
- shape_const = ov_opset .constant (np .array (out_shape , dtype = np .int64 )).output (0 )
945
- result = ov_opset .reshape (result , shape_const ).output (0 )
931
+ empty_array = np .array ([], dtype = np .dtype (dtype or config .floatx ()))
932
+ result = ov_opset .constant (empty_array ).output (0 )
946
933
947
934
if retstep :
948
935
delta = ov_opset .subtract (stop_ov , start_ov ).output (0 )
949
- step = delta
950
- return OpenVINOKerasTensor (result ), OpenVINOKerasTensor (step )
936
+ return OpenVINOKerasTensor (result ), OpenVINOKerasTensor (delta )
951
937
return OpenVINOKerasTensor (result )
952
938
953
- is_scalar_start = len (start_shape ) == 0
954
- is_scalar_stop = len (stop_shape ) == 0
955
-
956
- if not (is_scalar_start and is_scalar_stop ):
957
- broadcast_shape = list (np .broadcast (
958
- np .empty (start_shape , dtype = bool ),
959
- np .empty (stop_shape , dtype = bool )
960
- ).shape )
961
-
962
- if not is_scalar_start and tuple (start_shape ) != tuple (broadcast_shape ):
963
- shape_const = ov_opset .constant (np .array (broadcast_shape , dtype = np .int64 )).output (0 )
964
- start_ov = ov_opset .broadcast (start_ov , shape_const ).output (0 )
965
-
966
- if not is_scalar_stop and tuple (stop_shape ) != tuple (broadcast_shape ):
967
- shape_const = ov_opset .constant (np .array (broadcast_shape , dtype = np .int64 )).output (0 )
968
- stop_ov = ov_opset .broadcast (stop_ov , shape_const ).output (0 )
969
-
970
939
if num == 1 :
971
940
if endpoint :
972
- result = stop_ov
941
+ result = start_ov if retstep else stop_ov
973
942
else :
974
943
result = start_ov
975
944
976
- step = ov_opset .subtract (stop_ov , start_ov ).output (0 )
977
-
978
- if not (is_scalar_start and is_scalar_stop ):
979
- out_shape = list (result .get_shape ())
980
- out_shape .insert (axis , 1 )
981
- shape_const = ov_opset .constant (np .array (out_shape , dtype = np .int64 )).output (0 )
982
- result = ov_opset .reshape (result , shape_const ).output (0 )
983
- else :
984
- div = num - 1 if endpoint else num
985
- div_const = ov_opset .constant (div , ov_dtype ).output (0 )
986
- delta = ov_opset .subtract (stop_ov , start_ov ).output (0 )
987
- step = ov_opset .divide (delta , div_const ).output (0 )
988
-
989
- out_shape = list (start_ov .get_shape () if not is_scalar_start else stop_ov .get_shape () if not is_scalar_stop else [])
990
-
991
- indices = ov_opset .range (
992
- ov_opset .constant (0 , ov_dtype ).output (0 ),
993
- ov_opset .constant (num , ov_dtype ).output (0 ),
994
- ov_opset .constant (1 , ov_dtype ).output (0 )
995
- ).output (0 )
996
-
997
- if not (is_scalar_start and is_scalar_stop ):
998
- expanded_shape = list (out_shape )
999
- expanded_shape .insert (axis , 1 )
1000
- shape_const = ov_opset .constant (np .array (expanded_shape , dtype = np .int64 )).output (0 )
1001
-
1002
- start_reshaped = ov_opset .reshape (start_ov , shape_const ).output (0 )
1003
- step_reshaped = ov_opset .reshape (step , shape_const ).output (0 )
1004
-
1005
- indices_shape = [1 ] * len (expanded_shape )
1006
- indices_shape [axis ] = num
1007
- indices_shape_const = ov_opset .constant (np .array (indices_shape , dtype = np .int64 )).output (0 )
1008
- indices_reshaped = ov_opset .reshape (indices , indices_shape_const ).output (0 )
1009
-
1010
- indices_times_step = ov_opset .multiply (indices_reshaped , step_reshaped ).output (0 )
1011
- result = ov_opset .add (start_reshaped , indices_times_step ).output (0 )
1012
- else :
1013
- indices_times_step = ov_opset .multiply (indices , step ).output (0 )
1014
- result = ov_opset .add (start_ov , indices_times_step ).output (0 )
1015
-
1016
- if axis != 0 :
1017
- out_shape = [1 ] * (axis + 1 )
1018
- out_shape [axis ] = num
1019
- shape_const = ov_opset .constant (np .array (out_shape , dtype = np .int64 )).output (0 )
1020
- result = ov_opset .reshape (result , shape_const ).output (0 )
945
+ if retstep :
946
+ delta = ov_opset .subtract (stop_ov , start_ov ).output (0 )
947
+ return OpenVINOKerasTensor (result ), OpenVINOKerasTensor (delta )
948
+ return OpenVINOKerasTensor (result )
949
+
950
+ div = num - 1 if endpoint else num
951
+ div_const = ov_opset .constant (div , ov_dtype ).output (0 )
952
+ delta = ov_opset .subtract (stop_ov , start_ov ).output (0 )
953
+ step = ov_opset .divide (delta , div_const ).output (0 )
954
+
955
+ indices = ov_opset .range (
956
+ ov_opset .constant (0 , element_type = ov_dtype ).output (0 ),
957
+ ov_opset .constant (num , element_type = ov_dtype ).output (0 ),
958
+ ov_opset .constant (1 , element_type = ov_dtype ).output (0 ),
959
+ output_type = ov_dtype
960
+ ).output (0 )
961
+
962
+ scaled_indices = ov_opset .multiply (indices , step ).output (0 )
963
+ result = ov_opset .add (start_ov , scaled_indices ).output (0 )
964
+
965
+ if axis != 0 :
966
+ out_shape = [1 ] * (axis + 1 )
967
+ out_shape [axis ] = num
968
+ shape_const = ov_opset .constant (np .array (out_shape , dtype = np .int64 )).output (0 )
969
+ result = ov_opset .reshape (result , shape_const , special_zero = False ).output (0 )
1021
970
1022
971
if retstep :
1023
972
return OpenVINOKerasTensor (result ), OpenVINOKerasTensor (step )
1024
- return OpenVINOKerasTensor (result )
973
+ return OpenVINOKerasTensor (result )
1025
974
1026
975
1027
976
def log (x ):
0 commit comments