Example #1
0
def _check_unary_with_out_no_where_no_dtype(
        self, args, kw, impl, name_xp, name_in1, name_axis, name_indices,
        name_out, op, minval, maxval, shape, order_x, order_out, dtype_x,
        dtype_out, mode, is_broadcast, ufunc_name, axes, indices, keepdims):
    if mode == 'array':
        param = itertools.product(shape, order_x, order_out, dtype_x,
                                  dtype_out, axes, indices)
    elif mode == 'scalar':
        param = itertools.product(shape, order_out, dtype_x, dtype_out)
    else:
        raise TypeError('unknown mode was detected.')
    for p in param:
        if mode == 'array':
            in1 = ufunc._create_random_array(p[0], p[1], p[3], minval, maxval)
            in1 = _recreate_array_or_scalar(op, in1, ufunc_name)
            out = _create_out_array(p[0],
                                    p[2],
                                    p[4],
                                    ufunc_name,
                                    mode,
                                    axis=p[5],
                                    indices=p[6],
                                    keepdims=keepdims,
                                    is_broadcast=is_broadcast)
            worst_dtype = ufunc._guess_worst_dtype((in1.dtype, out.dtype))
            n_calc = _count_number_of_calculation(ufunc_name, p[0], p[5], p[6])
            if ufunc_name in ('reduce', 'accumulate', 'reduceat'):
                kw[name_axis] = p[5]
                if ufunc_name == 'reduceat':
                    kw[name_indices] = p[6]
        elif mode == 'scalar':
            in1 = ufunc._create_random_scalar(p[2], minval, maxval)
            in1 = _recreate_array_or_scalar(op, in1, ufunc_name)
            out = _create_out_array(p[0],
                                    p[1],
                                    p[3],
                                    ufunc_name,
                                    mode,
                                    is_broadcast=is_broadcast)
            worst_dtype = ufunc._guess_worst_dtype(
                (numpy.dtype(p[2]), out.dtype))
            n_calc = 1

        kw[name_in1] = in1
        kw[name_out] = out

        nlcpy_result, numpy_result = ufunc._precheck_func_for_ufunc(
            self, args, kw, impl, name_xp, op, True, Exception)
        # result check
        if nlcpy_result is not None and numpy_result is not None:
            for nlcpy_r, numpy_r in zip(nlcpy_result, numpy_result):
                ufunc._check_ufunc_result(op,
                                          worst_dtype,
                                          nlcpy_r,
                                          numpy_r,
                                          in1=in1,
                                          out=out,
                                          ufunc_name=ufunc_name,
                                          n_calc=n_calc)
Example #2
0
def _check_unary_no_out_no_where_with_dtype(self, args, kw, impl, name_xp,
                                            name_in1, name_axis, name_indices,
                                            name_dtype, op, minval, maxval,
                                            shape, order_x, dtype_x, dtype_arg,
                                            mode, ufunc_name, axes, indices):
    if mode == 'array':
        param = itertools.product(shape, order_x, dtype_x, dtype_arg, axes,
                                  indices)
    elif mode == 'scalar':
        param = itertools.product(dtype_x, dtype_arg)
    else:
        raise TypeError('unknown mode was detected.')
    for p in param:
        if mode == 'array':
            in1 = ufunc._create_random_array(p[0], p[1], p[2], minval, maxval)
            in1 = _recreate_array_or_scalar(op, in1, ufunc_name)
            dtype = numpy.dtype(p[3])
            if dtype == numpy.bool and op in float16_op:
                worst_dtype = ufunc._guess_worst_dtype(
                    (in1.dtype, numpy.dtype('f4')))
            else:
                worst_dtype = ufunc._guess_worst_dtype((in1.dtype, dtype))
            n_calc = _count_number_of_calculation(ufunc_name, p[0], p[4], p[5])
            if ufunc_name in ('reduce', 'accumulate', 'reduceat'):
                kw[name_axis] = p[4]
                if ufunc_name == 'reduceat':
                    kw[name_indices] = p[5]
        elif mode == 'scalar':
            in1 = ufunc._create_random_scalar(p[0], minval, maxval)
            in1 = _recreate_array_or_scalar(op, in1, ufunc_name)
            dtype = numpy.dtype(p[1])
            if dtype == numpy.bool and op in float16_op:
                worst_dtype = ufunc._guess_worst_dtype(
                    (in1.dtype, numpy.dtype('f4')))
            else:
                worst_dtype = ufunc._guess_worst_dtype(
                    (numpy.dtype(p[0]), dtype))
            n_calc = 1

        kw[name_in1] = in1
        kw[name_dtype] = dtype

        nlcpy_result, numpy_result = ufunc._precheck_func_for_ufunc(
            self, args, kw, impl, name_xp, op, True, Exception)
        # result check
        if nlcpy_result is not None and numpy_result is not None:
            for nlcpy_r, numpy_r in zip(nlcpy_result, numpy_result):
                ufunc._check_ufunc_result(op,
                                          worst_dtype,
                                          nlcpy_r,
                                          numpy_r,
                                          in1=in1,
                                          dtype=dtype,
                                          ufunc_name=ufunc_name,
                                          n_calc=n_calc)
Example #3
0
def _check_binary_no_out_no_where_no_dtype(self, args, kw, impl, name_xp,
                                           name_in1, name_in2, name_order,
                                           name_casting, op, minval, maxval,
                                           shape, order_x, order_y, order_arg,
                                           dtype_x, dtype_y, mode, ufunc_name,
                                           casting):
    if mode == 'array_array':
        param = itertools.product(shape, order_x, order_y, dtype_x, dtype_y,
                                  order_arg, casting)
    elif mode == 'array_scalar':
        param = itertools.product(shape, order_x, dtype_x, dtype_y, order_arg,
                                  casting)
    elif mode == 'scalar_scalar':
        param = itertools.product(dtype_x, dtype_y, casting)
    else:
        raise TypeError('unknown mode was detected.')
    for p in param:
        if mode == 'array_array':
            shape1 = p[0][0]
            shape2 = p[0][1]
            order = p[5]
            casting = p[6]
            in1 = ufunc._create_random_array(shape1, p[1], p[3], minval,
                                             maxval)
            in2 = ufunc._create_random_array(shape2, p[2], p[4], minval,
                                             maxval)
            in1, in2 = _recreate_array_or_scalar(op, in1, in2)
            worst_dtype = ufunc._guess_worst_dtype((in1.dtype, in2.dtype))
        elif mode == 'array_scalar':
            shape1 = p[0][0]
            order = p[4]
            casting = p[5]
            in1 = ufunc._create_random_array(shape1, p[1], p[2], minval,
                                             maxval)
            in2 = ufunc._create_random_scalar(p[3], minval, maxval)
            in1, in2 = _recreate_array_or_scalar(op, in1, in2)
            dt_in2 = numpy.dtype(p[3])
            worst_dtype = ufunc._guess_worst_dtype((in1.dtype, dt_in2))
        elif mode == 'scalar_scalar':
            casting = p[2]
            order = 'K'
            in1 = ufunc._create_random_scalar(p[0], minval, maxval)
            in2 = ufunc._create_random_scalar(p[1], minval, maxval)
            in1, in2 = _recreate_array_or_scalar(op, in1, in2)
            dt_in1 = numpy.dtype(p[0])
            dt_in2 = numpy.dtype(p[1])
            worst_dtype = ufunc._guess_worst_dtype((dt_in1, dt_in2))

        kw[name_in1] = in1
        kw[name_in2] = in2
        if ufunc_name == 'outer':
            kw[name_order] = order
            kw[name_casting] = casting

        nlcpy_result, numpy_result = ufunc._precheck_func_for_ufunc(
            self, args, kw, impl, name_xp, op, True, Exception)
        # result check
        if nlcpy_result is not None and numpy_result is not None:
            for nlcpy_r, numpy_r in zip(nlcpy_result, numpy_result):
                ufunc._check_ufunc_result(op,
                                          worst_dtype,
                                          nlcpy_r,
                                          numpy_r,
                                          in1=in1,
                                          in2=in2)
Example #4
0
def _check_binary_with_out_with_where_no_dtype(
        self, args, kw, impl, name_xp, name_in1, name_in2, name_order,
        name_casting, name_out, name_where, op, minval, maxval, shape, order_x,
        order_y, order_out, order_where, order_arg, dtype_x, dtype_y,
        dtype_out, mode, is_broadcast, ufunc_name, casting):
    if mode == 'array_array':
        param = itertools.product(shape, order_x, order_y, order_out,
                                  order_where, dtype_x, dtype_y, dtype_out,
                                  order_arg, casting)
    elif mode == 'array_scalar':
        param = itertools.product(shape, order_x, order_out, order_where,
                                  dtype_x, dtype_y, dtype_out, order_arg,
                                  casting)
    elif mode == 'scalar_scalar':
        param = itertools.product(order_out, order_where, dtype_x, dtype_y,
                                  dtype_out, casting)
    else:
        raise TypeError('unknown mode was detected.')
    for p in param:
        if mode == 'array_array':
            shape1 = p[0][0]
            shape2 = p[0][1]
            order = p[8]
            casting = p[9]
            in1 = ufunc._create_random_array(shape1, p[1], p[5], minval,
                                             maxval)
            in2 = ufunc._create_random_array(shape2, p[2], p[6], minval,
                                             maxval)
            in1, in2 = _recreate_array_or_scalar(op, in1, in2)
            out = _create_out_array(in1, in2, p[3], p[7], ufunc_name,
                                    is_broadcast)
            where = ufunc._create_random_array(out.shape, p[4], ufunc.DT_BOOL,
                                               minval, maxval)
            worst_dtype = ufunc._guess_worst_dtype(
                (in1.dtype, in2.dtype, out.dtype))
        elif mode == 'array_scalar':
            shape1 = p[0][0]
            order = p[7]
            casting = p[8]
            in1 = ufunc._create_random_array(shape1, p[1], p[4], minval,
                                             maxval)
            in2 = ufunc._create_random_scalar(p[5], minval, maxval)
            in1, in2 = _recreate_array_or_scalar(op, in1, in2)
            out = _create_out_array(in1, in2, p[2], p[6], ufunc_name,
                                    is_broadcast)
            where = ufunc._create_random_array(out.shape, p[3], ufunc.DT_BOOL,
                                               minval, maxval)
            dt_in2 = numpy.dtype(p[5])
            worst_dtype = ufunc._guess_worst_dtype(
                (in1.dtype, dt_in2, out.dtype))
        elif mode == 'scalar_scalar':
            order = 'K'
            casting = p[5]
            in1 = ufunc._create_random_scalar(p[2], minval, maxval)
            in2 = ufunc._create_random_scalar(p[3], minval, maxval)
            in1, in2 = _recreate_array_or_scalar(op, in1, in2)
            out = _create_out_array(in1, in2, p[0], p[4], ufunc_name,
                                    is_broadcast)
            where = ufunc._create_random_array(out.shape, p[1], ufunc.DT_BOOL,
                                               minval, maxval)
            dt_in1 = numpy.dtype(p[2])
            dt_in2 = numpy.dtype(p[3])
            worst_dtype = ufunc._guess_worst_dtype((dt_in1, dt_in2, out.dtype))

        # expand shape for broadcast
        if is_broadcast:
            where = numpy.resize(where, ((2, ) + where.shape))

        kw[name_in1] = in1
        kw[name_in2] = in2
        kw[name_out] = out
        kw[name_where] = where
        if ufunc_name == 'outer':
            kw[name_order] = order
            kw[name_casting] = casting

        nlcpy_result, numpy_result = ufunc._precheck_func_for_ufunc(
            self, args, kw, impl, name_xp, op, True, Exception)
        # result check
        if nlcpy_result is not None and numpy_result is not None:
            for nlcpy_r, numpy_r in zip(nlcpy_result, numpy_result):
                ufunc._check_ufunc_result(op,
                                          worst_dtype,
                                          nlcpy_r,
                                          numpy_r,
                                          in1=in1,
                                          in2=in2,
                                          out=out,
                                          where=where)