File tree Expand file tree Collapse file tree 12 files changed +129
-0
lines changed Expand file tree Collapse file tree 12 files changed +129
-0
lines changed Original file line number Diff line number Diff line change 219219from keras .src .ops .numpy import log2 as log2
220220from keras .src .ops .numpy import log10 as log10
221221from keras .src .ops .numpy import logaddexp as logaddexp
222+ from keras .src .ops .numpy import logaddexp2 as logaddexp2
222223from keras .src .ops .numpy import logical_and as logical_and
223224from keras .src .ops .numpy import logical_not as logical_not
224225from keras .src .ops .numpy import logical_or as logical_or
Original file line number Diff line number Diff line change 107107from keras .src .ops .numpy import log2 as log2
108108from keras .src .ops .numpy import log10 as log10
109109from keras .src .ops .numpy import logaddexp as logaddexp
110+ from keras .src .ops .numpy import logaddexp2 as logaddexp2
110111from keras .src .ops .numpy import logical_and as logical_and
111112from keras .src .ops .numpy import logical_not as logical_not
112113from keras .src .ops .numpy import logical_or as logical_or
Original file line number Diff line number Diff line change 219219from keras .src .ops .numpy import log2 as log2
220220from keras .src .ops .numpy import log10 as log10
221221from keras .src .ops .numpy import logaddexp as logaddexp
222+ from keras .src .ops .numpy import logaddexp2 as logaddexp2
222223from keras .src .ops .numpy import logical_and as logical_and
223224from keras .src .ops .numpy import logical_not as logical_not
224225from keras .src .ops .numpy import logical_or as logical_or
Original file line number Diff line number Diff line change 107107from keras .src .ops .numpy import log2 as log2
108108from keras .src .ops .numpy import log10 as log10
109109from keras .src .ops .numpy import logaddexp as logaddexp
110+ from keras .src .ops .numpy import logaddexp2 as logaddexp2
110111from keras .src .ops .numpy import logical_and as logical_and
111112from keras .src .ops .numpy import logical_not as logical_not
112113from keras .src .ops .numpy import logical_or as logical_or
Original file line number Diff line number Diff line change @@ -895,6 +895,15 @@ def logaddexp(x1, x2):
895895 return jnp .logaddexp (x1 , x2 )
896896
897897
898+ def logaddexp2 (x1 , x2 ):
899+ x1 = convert_to_tensor (x1 )
900+ x2 = convert_to_tensor (x2 )
901+ dtype = dtypes .result_type (x1 .dtype , x2 .dtype , float )
902+ x1 = cast (x1 , dtype )
903+ x2 = cast (x2 , dtype )
904+ return jnp .logaddexp2 (x1 , x2 )
905+
906+
898907def logical_and (x1 , x2 ):
899908 x1 = convert_to_tensor (x1 )
900909 x2 = convert_to_tensor (x2 )
Original file line number Diff line number Diff line change @@ -838,6 +838,13 @@ def logaddexp(x1, x2):
838838 return np .logaddexp (x1 , x2 )
839839
840840
841+ def logaddexp2 (x1 , x2 ):
842+ x1 = convert_to_tensor (x1 )
843+ x2 = convert_to_tensor (x2 )
844+ dtype = dtypes .result_type (x1 .dtype , x2 .dtype , float )
845+ return np .logaddexp2 (x1 , x2 ).astype (dtype )
846+
847+
841848def logical_and (x1 , x2 ):
842849 return np .logical_and (x1 , x2 )
843850
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ NumpyDtypeTest::test_isposinf
4040NumpyDtypeTest::test_kron
4141NumpyDtypeTest::test_lcm
4242NumpyDtypeTest::test_linspace
43+ NumpyDtypeTest::test_logaddexp2
4344NumpyDtypeTest::test_logspace
4445NumpyDtypeTest::test_matmul_
4546NumpyDtypeTest::test_max
@@ -95,6 +96,7 @@ NumpyOneInputOpsCorrectnessTest::test_imag
9596NumpyOneInputOpsCorrectnessTest::test_isfinite
9697NumpyOneInputOpsCorrectnessTest::test_isinf
9798NumpyOneInputOpsCorrectnessTest::test_isposinf
99+ NumpyOneInputOpsCorrectnessTest::test_logaddexp2
98100NumpyOneInputOpsCorrectnessTest::test_max
99101NumpyOneInputOpsCorrectnessTest::test_mean
100102NumpyOneInputOpsCorrectnessTest::test_median
Original file line number Diff line number Diff line change @@ -1142,6 +1142,12 @@ def logaddexp(x1, x2):
11421142 return OpenVINOKerasTensor (result )
11431143
11441144
1145+ def logaddexp2 (x1 , x2 ):
1146+ raise NotImplementedError (
1147+ "`logaddexp2` is not supported with openvino backend"
1148+ )
1149+
1150+
11451151def logical_and (x1 , x2 ):
11461152 x1 = get_ov_output (x1 )
11471153 x2 = get_ov_output (x2 )
Original file line number Diff line number Diff line change @@ -1910,6 +1910,22 @@ def logaddexp(x1, x2):
19101910 )
19111911
19121912
1913+ def logaddexp2 (x1 , x2 ):
1914+ x1 = tf .convert_to_tensor (x1 )
1915+ x2 = tf .convert_to_tensor (x2 )
1916+ dtype = dtypes .result_type (x1 .dtype , x2 .dtype , float )
1917+ x1 = tf .cast (x1 , dtype )
1918+ x2 = tf .cast (x2 , dtype )
1919+ delta = x1 - x2
1920+ log2 = tf .cast (tf .math .log (2.0 ), dtype )
1921+ return tf .where (
1922+ tf .math .is_nan (delta ),
1923+ x1 + x2 ,
1924+ tf .maximum (x1 , x2 )
1925+ + tf .math .log1p (tf .math .exp (- tf .abs (delta ) * log2 )) / log2 ,
1926+ )
1927+
1928+
19131929def logical_and (x1 , x2 ):
19141930 x1 = tf .cast (x1 , "bool" )
19151931 x2 = tf .cast (x2 , "bool" )
Original file line number Diff line number Diff line change @@ -1054,6 +1054,15 @@ def logaddexp(x1, x2):
10541054 return torch .logaddexp (x1 , x2 )
10551055
10561056
1057+ def logaddexp2 (x1 , x2 ):
1058+ x1 = convert_to_tensor (x1 )
1059+ x2 = convert_to_tensor (x2 )
1060+ dtype = dtypes .result_type (x1 .dtype , x2 .dtype , float )
1061+ x1 = cast (x1 , dtype )
1062+ x2 = cast (x2 , dtype )
1063+ return torch .logaddexp2 (x1 , x2 )
1064+
1065+
10571066def logical_and (x1 , x2 ):
10581067 x1 , x2 = convert_to_tensor (x1 ), convert_to_tensor (x2 )
10591068 return torch .logical_and (x1 , x2 )
You can’t perform that action at this time.
0 commit comments