Skip to content

Commit f67f5f1

Browse files
authored
Merge pull request #182 from SwayamInSync/conj
2 parents ae618c9 + ee98269 commit f67f5f1

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

quaddtype/numpy_quaddtype/src/ops.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ quad_absolute(const Sleef_quad *op)
3737
return Sleef_fabsq1(*op);
3838
}
3939

40+
static inline Sleef_quad
41+
quad_conjugate(const Sleef_quad *op)
42+
{
43+
// For real numbers, conjugate is the identity function (no-op)
44+
return *op;
45+
}
46+
4047
static inline Sleef_quad
4148
quad_rint(const Sleef_quad *op)
4249
{
@@ -257,6 +264,13 @@ ld_absolute(const long double *op)
257264
return fabsl(*op);
258265
}
259266

267+
static inline long double
268+
ld_conjugate(const long double *op)
269+
{
270+
// For real numbers, conjugate is the identity function (no-op)
271+
return *op;
272+
}
273+
260274
static inline long double
261275
ld_sign(const long double *op)
262276
{

quaddtype/numpy_quaddtype/src/umath/unary_ops.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ init_quad_unary_ops(PyObject *numpy)
161161
if (create_quad_unary_ufunc<quad_absolute, ld_absolute>(numpy, "fabs") < 0) {
162162
return -1;
163163
}
164+
// conjugate is a no-op for real numbers (returns the value unchanged)
165+
if (create_quad_unary_ufunc<quad_conjugate, ld_conjugate>(numpy, "conjugate") < 0) {
166+
return -1;
167+
}
168+
// conj is an alias for conjugate, no need to register
164169
if (create_quad_unary_ufunc<quad_sign, ld_sign>(numpy, "sign") < 0) {
165170
return -1;
166171
}

quaddtype/release_tracker.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
| rint |||
2828
| sign |||
2929
| heaviside |||
30+
| conj |||
31+
| conjugate |||
32+
| heaviside |||
3033
| conj | | |
3134
| conjugate | | |
3235
| exp |||
@@ -40,8 +43,6 @@
4043
| square |||
4144
| cbrt |||
4245
| reciprocal |||
43-
| gcd | | |
44-
| lcm | | |
4546
| sin ||_Need: basic tests + edge cases (NaN/inf/0/π multiples/2π range)_ |
4647
| cos ||_Need: basic tests + edge cases (NaN/inf/0/π multiples/2π range)_ |
4748
| tan ||_Need: basic tests + edge cases (NaN/inf/0/π/2 asymptotes)_ |

quaddtype/tests/test_quaddtype.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,3 +1837,25 @@ def test_heaviside_broadcast():
18371837
assert result.dtype.name == "QuadPrecDType128"
18381838
np.testing.assert_array_equal(result.astype(float), expected)
18391839

1840+
1841+
@pytest.mark.parametrize("func", [np.conj, np.conjugate])
1842+
@pytest.mark.parametrize("value", [
1843+
0.0,
1844+
-0.0,
1845+
1.5,
1846+
-1.5,
1847+
np.inf,
1848+
-np.inf,
1849+
np.nan,
1850+
])
1851+
def test_conj_conjugate_identity(func, value):
1852+
"""Test that conj and conjugate are identity (no-op) for real quad precision numbers"""
1853+
x = QuadPrecision(value)
1854+
result = func(x)
1855+
1856+
# For NaN, use special comparison
1857+
if np.isnan(value):
1858+
assert np.isnan(float(result))
1859+
else:
1860+
assert result == x
1861+

0 commit comments

Comments
 (0)