Skip to content

Commit 0ac5464

Browse files
committed
added more unary func
1 parent 755e2cd commit 0ac5464

File tree

4 files changed

+126
-5
lines changed

4 files changed

+126
-5
lines changed

quaddtype/numpy_quaddtype/src/dtype.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,21 @@ quad_store(char *data_ptr, void *x, QuadBackendType backend)
5050
QuadPrecDTypeObject *
5151
new_quaddtype_instance(QuadBackendType backend)
5252
{
53+
QuadBackendType target_backend = backend;
5354
if (backend != BACKEND_SLEEF && backend != BACKEND_LONGDOUBLE) {
5455
PyErr_SetString(PyExc_TypeError, "Backend must be sleef or longdouble");
5556
return NULL;
57+
// target_backend = BACKEND_SLEEF;
5658
}
5759

5860
QuadPrecDTypeObject *new = (QuadPrecDTypeObject *)PyArrayDescr_Type.tp_new(
5961
(PyTypeObject *)&QuadPrecDType, NULL, NULL);
6062
if (new == NULL) {
6163
return NULL;
6264
}
63-
new->base.elsize = (backend == BACKEND_SLEEF) ? sizeof(Sleef_quad) : sizeof(long double);
64-
new->base.alignment = (backend == BACKEND_SLEEF) ? _Alignof(Sleef_quad) : _Alignof(long double);
65-
new->backend = backend;
65+
new->base.elsize = (target_backend == BACKEND_SLEEF) ? sizeof(Sleef_quad) : sizeof(long double);
66+
new->base.alignment = (target_backend == BACKEND_SLEEF) ? _Alignof(Sleef_quad) : _Alignof(long double);
67+
new->backend = target_backend;
6668
return new;
6769
}
6870

quaddtype/numpy_quaddtype/src/ops.hpp

+99
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,49 @@ quad_exp2(Sleef_quad *op, Sleef_quad *out)
110110
return 0;
111111
}
112112

113+
static inline int
114+
quad_sin(Sleef_quad *op, Sleef_quad *out)
115+
{
116+
*out = Sleef_sinq1_u10(*op);
117+
return 0;
118+
}
119+
120+
static inline int
121+
quad_cos(Sleef_quad *op, Sleef_quad *out)
122+
{
123+
*out = Sleef_cosq1_u10(*op);
124+
return 0;
125+
}
126+
127+
static inline int
128+
quad_tan(Sleef_quad *op, Sleef_quad *out)
129+
{
130+
*out = Sleef_tanq1_u10(*op);
131+
return 0;
132+
}
133+
134+
static inline int
135+
quad_asin(Sleef_quad *op, Sleef_quad *out)
136+
{
137+
*out = Sleef_asinq1_u10(*op);
138+
return 0;
139+
}
140+
141+
static inline int
142+
quad_acos(Sleef_quad *op, Sleef_quad *out)
143+
{
144+
*out = Sleef_acosq1_u10(*op);
145+
return 0;
146+
}
147+
148+
static inline int
149+
quad_atan(Sleef_quad *op, Sleef_quad *out)
150+
{
151+
*out = Sleef_atanq1_u10(*op);
152+
return 0;
153+
}
154+
155+
113156
// Unary long double operations
114157
typedef int (*unary_op_longdouble_def)(long double *, long double *);
115158

@@ -218,6 +261,48 @@ ld_exp2(long double *op, long double *out)
218261
return 0;
219262
}
220263

264+
static inline int
265+
ld_sin(long double *op, long double *out)
266+
{
267+
*out = sinl(*op);
268+
return 0;
269+
}
270+
271+
static inline int
272+
ld_cos(long double *op, long double *out)
273+
{
274+
*out = cosl(*op);
275+
return 0;
276+
}
277+
278+
static inline int
279+
ld_tan(long double *op, long double *out)
280+
{
281+
*out = tanl(*op);
282+
return 0;
283+
}
284+
285+
static inline int
286+
ld_asin(long double *op, long double *out)
287+
{
288+
*out = asinl(*op);
289+
return 0;
290+
}
291+
292+
static inline int
293+
ld_acos(long double *op, long double *out)
294+
{
295+
*out = acosl(*op);
296+
return 0;
297+
}
298+
299+
static inline int
300+
ld_atan(long double *op, long double *out)
301+
{
302+
*out = atanl(*op);
303+
return 0;
304+
}
305+
221306
// Binary Quad operations
222307
typedef int (*binary_op_quad_def)(Sleef_quad *, Sleef_quad *, Sleef_quad *);
223308

@@ -277,6 +362,13 @@ quad_maximum(Sleef_quad *out, Sleef_quad *in1, Sleef_quad *in2)
277362
return 0;
278363
}
279364

365+
static inline int
366+
quad_atan2(Sleef_quad *out, Sleef_quad *in1, Sleef_quad *in2)
367+
{
368+
*out = Sleef_atan2q1_u10(*in1, *in2);
369+
return 0;
370+
}
371+
280372
// Binary long double operations
281373
typedef int (*binary_op_longdouble_def)(long double *, long double *, long double *);
282374

@@ -336,6 +428,13 @@ ld_maximum(long double *out, long double *in1, long double *in2)
336428
return 0;
337429
}
338430

431+
static inline int
432+
ld_atan2(long double *out, long double *in1, long double *in2)
433+
{
434+
*out = atan2l(*in1, *in2);
435+
return 0;
436+
}
437+
339438
// comparison quad functions
340439
typedef npy_bool (*cmp_quad_def)(const Sleef_quad *, const Sleef_quad *);
341440

quaddtype/numpy_quaddtype/src/scalar.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,6 @@ PyTypeObject QuadPrecision_Type = {
232232
int
233233
init_quadprecision_scalar(void)
234234
{
235-
QuadPrecision_Type.tp_base = &PyFloat_Type; // this is not working (subclassing to np.floating)
235+
// QuadPrecision_Type.tp_base = &PyFloatingArrType_Type;
236236
return PyType_Ready(&QuadPrecision_Type);
237237
}

quaddtype/numpy_quaddtype/src/umath.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ init_quad_unary_ops(PyObject *numpy)
217217
if (create_quad_unary_ufunc<quad_exp2, ld_exp2>(numpy, "exp2") < 0) {
218218
return -1;
219219
}
220+
if (create_quad_unary_ufunc<quad_sin, ld_sin>(numpy, "sin") < 0) {
221+
return -1;
222+
}
223+
if (create_quad_unary_ufunc<quad_cos, ld_cos>(numpy, "cos") < 0) {
224+
return -1;
225+
}
226+
if (create_quad_unary_ufunc<quad_tan, ld_tan>(numpy, "tan") < 0) {
227+
return -1;
228+
}
229+
if (create_quad_unary_ufunc<quad_asin, ld_asin>(numpy, "arcsin") < 0) {
230+
return -1;
231+
}
232+
if (create_quad_unary_ufunc<quad_acos, ld_acos>(numpy, "arccos") < 0) {
233+
return -1;
234+
}
235+
if (create_quad_unary_ufunc<quad_atan, ld_atan>(numpy, "arctan") < 0) {
236+
return -1;
237+
}
220238
return 0;
221239
}
222240

@@ -315,7 +333,6 @@ static int
315333
quad_ufunc_promoter(PyUFuncObject *ufunc, PyArray_DTypeMeta *op_dtypes[],
316334
PyArray_DTypeMeta *signature[], PyArray_DTypeMeta *new_op_dtypes[])
317335
{
318-
319336
int nin = ufunc->nin;
320337
int nargs = ufunc->nargs;
321338
PyArray_DTypeMeta *common = NULL;
@@ -473,6 +490,9 @@ init_quad_binary_ops(PyObject *numpy)
473490
if (create_quad_binary_ufunc<quad_maximum, ld_maximum>(numpy, "maximum") < 0) {
474491
return -1;
475492
}
493+
if (create_quad_binary_ufunc<quad_atan2, ld_atan2>(numpy, "arctan2") < 0) {
494+
return -1;
495+
}
476496
return 0;
477497
}
478498

0 commit comments

Comments
 (0)