@@ -3697,6 +3697,57 @@ def test_array_conjugate_method():
36973697 np .testing .assert_array_equal (result .astype (float ), [1.5 , - 2.5 , 0.0 ])
36983698
36993699
3700+ @pytest .mark .parametrize ("backend" , ["sleef" , "longdouble" ])
3701+ def test_object_conjugate_preserves_values_and_backend (backend ):
3702+ dtype = QuadPrecDType (backend = backend )
3703+ objects = np .array ([1.5 , 2.5 ], dtype = dtype ).astype (object )
3704+
3705+ result = np .conjugate (objects )
3706+
3707+ np .testing .assert_array_equal (result , objects , strict = True )
3708+ for scalar in result :
3709+ assert scalar .dtype == dtype
3710+
3711+
3712+ @pytest .mark .parametrize ("backend" , ["sleef" , "longdouble" ])
3713+ @pytest .mark .parametrize ("method" , ["conj" , "conjugate" ])
3714+ @pytest .mark .parametrize ("value" , [1.5 , - 0.0 , np .inf , np .nan ])
3715+ @pytest .mark .parametrize ("args" , [(), (None ,)])
3716+ def test_scalar_conjugate_preserves_values_and_backend (backend , method , value , args ):
3717+ scalar = QuadPrecision (value , backend = backend )
3718+
3719+ result = getattr (scalar , method )(* args )
3720+
3721+ assert result .dtype == scalar .dtype
3722+ np .testing .assert_array_equal (float (result ), value )
3723+ assert np .signbit (float (result )) == np .signbit (value )
3724+
3725+
3726+ @pytest .mark .parametrize ("backend" , ["sleef" , "longdouble" ])
3727+ @pytest .mark .parametrize ("method" , ["conj" , "conjugate" ])
3728+ @pytest .mark .parametrize ("dtype" , [np .float32 , np .float64 , object , QuadPrecDType ])
3729+ def test_scalar_conjugate_with_out (backend , method , dtype ):
3730+ scalar = QuadPrecision (1.5 , backend = backend )
3731+ out = np .empty ((), dtype = scalar .dtype if dtype is QuadPrecDType else dtype )
3732+ reference_out = np .empty ((), dtype = np .float64 if dtype is QuadPrecDType else dtype )
3733+
3734+ result = getattr (scalar , method )(out )
3735+ expected = getattr (np .float64 (1.5 ), method )(reference_out )
3736+
3737+ np .testing .assert_array_equal (float (result ), float (expected ))
3738+ np .testing .assert_array_equal (out .astype (np .float64 ), reference_out .astype (np .float64 ))
3739+ if dtype is object or dtype is QuadPrecDType :
3740+ assert result .dtype == scalar .dtype
3741+
3742+
3743+ @pytest .mark .parametrize ("backend" , ["sleef" , "longdouble" ])
3744+ @pytest .mark .parametrize ("method" , ["conj" , "conjugate" ])
3745+ @pytest .mark .parametrize ("args" , [(1 ,), (None , None ), (np .empty ((), dtype = np .int64 ),)])
3746+ def test_scalar_conjugate_rejects_invalid_out (backend , method , args ):
3747+ for scalar in [QuadPrecision (1.5 , backend = backend ), np .float64 (1.5 )]:
3748+ with pytest .raises (TypeError ):
3749+ getattr (scalar , method )(* args )
3750+
37003751@pytest .mark .parametrize ("x1,x2,expected" , [
37013752 # Basic Pythagorean triples
37023753 (3.0 , 4.0 , 5.0 ),
0 commit comments