Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions quaddtype/numpy_quaddtype/src/ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ quad_absolute(const Sleef_quad *op)
return Sleef_fabsq1(*op);
}

static inline Sleef_quad
quad_conjugate(const Sleef_quad *op)
{
// For real numbers, conjugate is the identity function (no-op)
return *op;
}

static inline Sleef_quad
quad_rint(const Sleef_quad *op)
{
Expand Down Expand Up @@ -217,6 +224,13 @@ ld_absolute(const long double *op)
return fabsl(*op);
}

static inline long double
ld_conjugate(const long double *op)
{
// For real numbers, conjugate is the identity function (no-op)
return *op;
}

static inline long double
ld_sign(const long double *op)
{
Expand Down
5 changes: 5 additions & 0 deletions quaddtype/numpy_quaddtype/src/umath/unary_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ init_quad_unary_ops(PyObject *numpy)
if (create_quad_unary_ufunc<quad_absolute, ld_absolute>(numpy, "fabs") < 0) {
return -1;
}
// conjugate is a no-op for real numbers (returns the value unchanged)
if (create_quad_unary_ufunc<quad_conjugate, ld_conjugate>(numpy, "conjugate") < 0) {
return -1;
}
// conj is an alias for conjugate, no need to register
if (create_quad_unary_ufunc<quad_sign, ld_sign>(numpy, "sign") < 0) {
return -1;
}
Expand Down
5 changes: 3 additions & 2 deletions quaddtype/release_tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
| rint | ✅ | ✅ |
| sign | ✅ | ✅ |
| heaviside | ✅ | ✅ |
| conj | ✅ | ✅ |
| conjugate | ✅ | ✅ |
| heaviside | ✅ | ✅ |
| conj | | |
| conjugate | | |
| exp | ✅ | ✅ |
Expand All @@ -40,8 +43,6 @@
| square | ✅ | ✅ |
| cbrt | | |
| reciprocal | ✅ | ✅ |
| gcd | | |
| lcm | | |
| sin | ✅ | ❌ _Need: basic tests + edge cases (NaN/inf/0/π multiples/2π range)_ |
| cos | ✅ | ❌ _Need: basic tests + edge cases (NaN/inf/0/π multiples/2π range)_ |
| tan | ✅ | ❌ _Need: basic tests + edge cases (NaN/inf/0/π/2 asymptotes)_ |
Expand Down
22 changes: 22 additions & 0 deletions quaddtype/tests/test_quaddtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,3 +1693,25 @@ def test_heaviside_broadcast():
assert result.dtype.name == "QuadPrecDType128"
np.testing.assert_array_equal(result.astype(float), expected)


@pytest.mark.parametrize("func", [np.conj, np.conjugate])
@pytest.mark.parametrize("value", [
0.0,
-0.0,
1.5,
-1.5,
np.inf,
-np.inf,
np.nan,
])
def test_conj_conjugate_identity(func, value):
"""Test that conj and conjugate are identity (no-op) for real quad precision numbers"""
x = QuadPrecision(value)
result = func(x)

# For NaN, use special comparison
if np.isnan(value):
assert np.isnan(float(result))
else:
assert result == x

Loading