939
*****************************************************************************
941
*****************************************************************************
945
* #type = datetime, timedelta#
946
* #TYPE = DATETIME, TIMEDELTA#
947
* #ftype = double, double#
951
@TYPE@_ones_like(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(data))
954
*((@type@ *)op1) = 1;
959
@TYPE@_negative(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
962
const @type@ in1 = *(@type@ *)ip1;
963
*((@type@ *)op1) = (@type@)(-(@type@)in1);
968
@TYPE@_logical_not(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
971
const @type@ in1 = *(@type@ *)ip1;
972
*((Bool *)op1) = !in1;
978
* #kind = equal, not_equal, greater, greater_equal, less, less_equal,
979
* logical_and, logical_or#
980
* #OP = ==, !=, >, >=, <, <=, &&, ||#
983
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
986
const @type@ in1 = *(@type@ *)ip1;
987
const @type@ in2 = *(@type@ *)ip2;
988
*((Bool *)op1) = in1 @OP@ in2;
994
@TYPE@_logical_xor(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
997
const @type@ in1 = *(@type@ *)ip1;
998
const @type@ in2 = *(@type@ *)ip2;
999
*((Bool *)op1)= (in1 && !in2) || (!in1 && in2);
1004
* #kind = maximum, minimum#
1008
@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1010
if (IS_BINARY_REDUCE) {
1011
BINARY_REDUCE_LOOP(@type@) {
1012
const @type@ in2 = *(@type@ *)ip2;
1013
io1 = (io1 @OP@ in2) ? io1 : in2;
1015
*((@type@ *)iop1) = io1;
1019
const @type@ in1 = *(@type@ *)ip1;
1020
const @type@ in2 = *(@type@ *)ip2;
1021
*((@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
1028
@TYPE@_absolute(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1031
const @type@ in1 = *(@type@ *)ip1;
1032
*((@type@ *)op1) = (in1 >= 0) ? in1 : -in1;
1037
@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1040
const @type@ in1 = *(@type@ *)ip1;
1041
*((@type@ *)op1) = in1 > 0 ? 1 : (in1 < 0 ? -1 : 0);
1047
/* FIXME: implement the following correctly using the metadata: data is the
1048
sequence of ndarrays in the same order as args.
1051
DATETIME_Mm_M_add(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(data))
1054
const datetime in1 = *(datetime *)ip1;
1055
const timedelta in2 = *(timedelta *)ip2;
1056
*((datetime *)op1) = in1 + in2;
1061
DATETIME_mM_M_add(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1064
const timedelta in1 = *(timedelta *)ip1;
1065
const datetime in2 = *(datetime *)ip2;
1066
*((datetime *)op1) = in1 + in2;
1071
TIMEDELTA_mm_m_add(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1074
const timedelta in1 = *(timedelta *)ip1;
1075
const timedelta in2 = *(timedelta *)ip2;
1076
*((timedelta *)op1) = in1 + in2;
1081
DATETIME_Mm_M_subtract(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1084
const datetime in1 = *(datetime *)ip1;
1085
const timedelta in2 = *(timedelta *)ip2;
1086
*((datetime *)op1) = in1 - in2;
1091
DATETIME_MM_m_subtract(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1094
const datetime in1 = *(datetime *)ip1;
1095
const datetime in2 = *(datetime *)ip2;
1096
*((timedelta *)op1) = in1 - in2;
1101
TIMEDELTA_mm_m_subtract(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1104
const timedelta in1 = *(timedelta *)ip1;
1105
const timedelta in2 = *(timedelta *)ip2;
1106
*((timedelta *)op1) = in1 - in2;
854
1112
*****************************************************************************
1160
1434
/**end repeat**/
1437
*****************************************************************************
1438
** HALF-FLOAT LOOPS **
1439
*****************************************************************************
1445
* # kind = add, subtract, multiply, divide#
1446
* # OP = +, -, *, /#
1449
HALF_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1451
if(IS_BINARY_REDUCE) {
1452
char *iop1 = args[0];
1453
float io1 = npy_half_to_float(*(npy_half *)iop1);
1454
BINARY_REDUCE_LOOP_INNER {
1455
io1 @OP@= npy_half_to_float(*(npy_half *)ip2);
1457
*((npy_half *)iop1) = npy_float_to_half(io1);
1461
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1462
const float in2 = npy_half_to_float(*(npy_half *)ip2);
1463
*((npy_half *)op1) = npy_float_to_half(in1 @OP@ in2);
1469
#define _HALF_LOGICAL_AND(a,b) (!npy_half_iszero(a) && !npy_half_iszero(b))
1470
#define _HALF_LOGICAL_OR(a,b) (!npy_half_iszero(a) || !npy_half_iszero(b))
1472
* #kind = equal, not_equal, less, less_equal, greater, greater_equal,
1473
* logical_and, logical_or#
1474
* #OP = npy_half_eq, npy_half_ne, npy_half_lt, npy_half_le, npy_half_gt, npy_half_ge, _HALF_LOGICAL_AND, _HALF_LOGICAL_OR#
1477
HALF_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1480
const npy_half in1 = *(npy_half *)ip1;
1481
const npy_half in2 = *(npy_half *)ip2;
1482
*((Bool *)op1) = @OP@(in1, in2);
1486
#undef _HALF_LOGICAL_AND
1487
#undef _HALF_LOGICAL_OR
1490
HALF_logical_xor(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1493
const int in1 = !npy_half_iszero(*(npy_half *)ip1);
1494
const int in2 = !npy_half_iszero(*(npy_half *)ip2);
1495
*((Bool *)op1)= (in1 && !in2) || (!in1 && in2);
1500
HALF_logical_not(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1503
const npy_half in1 = *(npy_half *)ip1;
1504
*((Bool *)op1) = npy_half_iszero(in1);
1509
* #kind = isnan, isinf, isfinite, signbit#
1510
* #func = npy_half_isnan, npy_half_isinf, npy_half_isfinite, npy_half_signbit#
1513
HALF_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1516
const npy_half in1 = *(npy_half *)ip1;
1517
*((Bool *)op1) = @func@(in1) != 0;
1523
HALF_spacing(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1526
const npy_half in1 = *(npy_half *)ip1;
1527
*((npy_half *)op1) = npy_half_spacing(in1);
1532
HALF_copysign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1535
const npy_half in1 = *(npy_half *)ip1;
1536
const npy_half in2 = *(npy_half *)ip2;
1537
*((npy_half *)op1)= npy_half_copysign(in1, in2);
1542
HALF_nextafter(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1545
const npy_half in1 = *(npy_half *)ip1;
1546
const npy_half in2 = *(npy_half *)ip2;
1547
*((npy_half *)op1)= npy_half_nextafter(in1, in2);
1552
* #kind = maximum, minimum#
1553
* #OP = npy_half_ge, npy_half_le#
1556
HALF_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1560
const npy_half in1 = *(npy_half *)ip1;
1561
const npy_half in2 = *(npy_half *)ip2;
1562
*((npy_half *)op1) = (@OP@(in1, in2) || npy_half_isnan(in1)) ? in1 : in2;
1568
* #kind = fmax, fmin#
1569
* #OP = npy_half_ge, npy_half_le#
1572
HALF_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1576
const npy_half in1 = *(npy_half *)ip1;
1577
const npy_half in2 = *(npy_half *)ip2;
1578
*((npy_half *)op1) = (@OP@(in1, in2) || npy_half_isnan(in2)) ? in1 : in2;
1584
HALF_floor_divide(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1587
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1588
const float in2 = npy_half_to_float(*(npy_half *)ip2);
1589
*((npy_half *)op1) = npy_float_to_half(npy_floorf(in1/in2));
1594
HALF_remainder(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1597
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1598
const float in2 = npy_half_to_float(*(npy_half *)ip2);
1599
const float res = npy_fmodf(in1,in2);
1600
if (res && ((in2 < 0) != (res < 0))) {
1601
*((npy_half *)op1) = npy_float_to_half(res + in2);
1604
*((npy_half *)op1) = npy_float_to_half(res);
1610
HALF_square(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(data))
1613
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1614
*((npy_half *)op1) = npy_float_to_half(in1*in1);
1619
HALF_reciprocal(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(data))
1622
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1623
*((npy_half *)op1) = npy_float_to_half(1/in1);
1628
HALF_ones_like(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(data))
1631
*((npy_half *)op1) = NPY_HALF_ONE;
1636
HALF_conjugate(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1639
const npy_half in1 = *(npy_half *)ip1;
1640
*((npy_half *)op1) = in1;
1645
HALF_absolute(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1648
const npy_half in1 = *(npy_half *)ip1;
1649
*((npy_half *)op1) = in1&0x7fffu;
1654
HALF_negative(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1657
const npy_half in1 = *(npy_half *)ip1;
1658
*((npy_half *)op1) = in1^0x8000u;
1663
HALF_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1665
/* Sign of nan is nan */
1667
const npy_half in1 = *(npy_half *)ip1;
1668
*((npy_half *)op1) = npy_half_isnan(in1) ? in1 :
1669
(((in1&0x7fffu) == 0) ? 0 :
1670
(((in1&0x8000u) == 0) ? NPY_HALF_ONE : NPY_HALF_NEGONE));
1675
HALF_modf(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1679
UNARY_LOOP_TWO_OUT {
1680
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1681
*((npy_half *)op1) = npy_float_to_half(npy_modff(in1, &temp));
1682
*((npy_half *)op2) = npy_float_to_half(temp);
1688
HALF_frexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1690
UNARY_LOOP_TWO_OUT {
1691
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1692
*((npy_half *)op1) = npy_float_to_half(frexpf(in1, (int *)op2));
1699
HALF_ldexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1702
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1703
const int in2 = *(int *)ip2;
1704
*((npy_half *)op1) = npy_float_to_half(ldexpf(in1, in2));
1709
HALF_ldexp_long(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
1712
* Additional loop to handle long integer inputs (cf. #866, #1633).
1713
* long != int on many 64-bit platforms, so we need this second loop
1714
* to handle the default integer type.
1717
const float in1 = npy_half_to_float(*(npy_half *)ip1);
1718
const long in2 = *(long *)ip2;
1719
if (((int)in2) == in2) {
1721
*((npy_half *)op1) = npy_float_to_half(ldexpf(in1, ((int)in2)));
1725
* Outside int range -- also ldexp will overflow in this case,
1726
* given that exponent has less bits than int.
1729
*((npy_half *)op1) = npy_float_to_half(ldexpf(in1, NPY_MAX_INT));
1732
*((npy_half *)op1) = npy_float_to_half(ldexpf(in1, NPY_MIN_INT));
1739
#define HALF_true_divide HALF_divide
1164
1743
*****************************************************************************