arrayfire icon indicating copy to clipboard operation
arrayfire copied to clipboard

[BUG] FP16 Types Not Allowed for Atan2 Method

Open AzeezIsh opened this issue 1 year ago • 1 comments

Manual type assertions not allowing FP16 types not allowing for atan2. Has not been updated to allow FP16.

Description

https://github.com/arrayfire/arrayfire/blob/4061db86e66306995175a14cf906c55c35373918/src/api/c/binary.cpp#L479

Reproducible Code and/or Steps

shape = (4, 7, 4, 9), dtype_name = arrayfire.float16(typecode)

@pytest.mark.parametrize(
    "shape",
    [
        (),
        (random.randint(1, 10),),
        (random.randint(1, 10), random.randint(1, 10)),
        (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
        (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
    ],
)
@pytest.mark.parametrize("dtype_name", util.get_float_types())
def test_atan2_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
    """Test inverse tan operation across all supported data types."""
    util.check_type_supported(dtype_name)
    lhs = wrapper.randu(shape, dtype_name)
    rhs = wrapper.randu(shape, dtype_name)
  result = wrapper.atan2(lhs, rhs)

tests/test_trig.py:121:


arrayfire_wrapper/lib/mathematical_functions/trigonometric_functions.py:30: in atan2 return binary_op(atan2.name, lhs, rhs) arrayfire_wrapper/lib/_utility.py:15: in binary_op call_from_clib(c_func_name, ctypes.pointer(out), lhs, rhs, bcast_var.get()) arrayfire_wrapper/lib/_utility.py:32: in call_from_clib _process_error(backend)


backend = <arrayfire_wrapper._backend.Backend object at 0x7fe5af859d20>

def _process_error(backend: Backend) -> None:
    err_str = ctypes.c_char_p(0)
    err_len = CDimT(0)
    backend.clib.af_get_last_error(ctypes.pointer(err_str), ctypes.pointer(err_len))
  raise RuntimeError(to_str(err_str))

E RuntimeError: In function af_atan2 E In file src/api/c/binary.cpp:480 E Only floating point arrays are supported for atan2

AzeezIsh avatar Mar 20 '24 21:03 AzeezIsh

This issue may also affect the following functions:

src/backend/common/util.cpp:getName src/api/c/diff.cpp:af_diff1 src/api/c/diff.cpp:af_diff2 src/api/c/sort.cpp:af_sort src/api/c/sort.cpp:sort_index src/api/c/cholesky.cpp:af_cholesky src/api/c/cholesky.cpp:af_cholesky_inplace src/api/c/pinverse.cpp:af_pinverse src/api/c/regions.cpp:regions src/api/c/where.cpp:af_where src/api/c/sobel.cpp:af_sobel_operator src/api/c/median.cpp:af_median src/api/c/median.cpp:af_median_all src/api/c/dog.cpp:af_dog src/api/c/resize.cpp:af_resize src/api/c/fast.cpp:af_fast src/api/c/image.cpp:af_draw_image src/api/c/unwrap.cpp:af_unwrap src/api/c/transform_coordinates.cpp:af_transform_coordinates src/api/c/norm.cpp:af_norm src/api/c/filters.cpp:af_medfilt1 src/api/c/filters.cpp:af_medfilt2 src/api/c/susan.cpp:af_susan src/api/c/fft.cpp:fft src/api/c/fft.cpp:fft_r2c src/api/c/det.cpp:af_det src/api/c/stream.cpp:af_save_array src/api/c/stream.cpp:readArrayV1 src/api/c/svd.cpp:af_svd src/api/c/svd.cpp:svd_inplace src/api/c/moments.cpp:af_moments src/api/c/orb.cpp:af_orb src/api/c/scan.cpp:af_accum src/api/c/scan.cpp:af_scan src/api/c/scan.cpp:af_scan_by_key src/api/c/gradient.cpp:af_gradient src/api/c/set.cpp:af_set_unique src/api/c/set.cpp:af_set_union src/api/c/set.cpp:af_set_intersect src/api/c/qr.cpp:af_qr src/api/c/qr.cpp:af_qr_inplace src/api/c/convolve.cpp:convolve src/api/c/convolve.cpp:convolve2_sep src/api/c/morph.cpp:morph src/api/c/morph.cpp:morph3d src/api/c/bilateral.cpp:af_bilateral src/api/c/stdev.cpp:stdev_v2 src/api/c/stdev.cpp:stdev_all_v2 src/api/c/topk.cpp:af_topk src/api/c/inverse.cpp:af_inverse src/api/c/lu.cpp:af_lu src/api/c/lu.cpp:af_lu_inplace src/api/c/meanshift.cpp:af_mean_shift src/api/c/shift.cpp:af_shift src/api/c/rank.cpp:af_rank src/api/c/exampleFunction.cpp:af_example_function src/api/c/reduce.cpp:ireduce_all_common src/api/c/canny.cpp:af_canny src/api/c/sift.cpp:sift src/api/c/sift.cpp:gloh src/api/c/fftconvolve.cpp:fft_convolve src/api/c/confidence_connected.cpp:af_confidence_cc (also f64 missing) src/api/c/solve.cpp:af_solve src/api/c/solve.cpp:af_solve_lu src/api/c/nearest_neighbour.cpp:af_nearest_neighbour src/api/c/approx.cpp:af_approx1_common src/api/c/approx.cpp:af_approx2_common src/api/c/rotate.cpp:af_rotate src/api/c/deconvolution.cpp:af_iterative_deconv src/api/c/deconvolution.cpp:af_inverse_deconv src/api/c/homography.cpp:af_homography src/api/c/covariance.cpp:af_cov_v2 src/api/c/hsv_rgb.cpp:convert src/api/c/histeq.cpp:af_hist_equal src/api/c/corrcoef.cpp:af_corrcoef src/api/c/anisotropic_diffusion.cpp:af_anisotropic_diffusion src/api/c/hist.cpp:af_draw_hist (also f64 missing) src/api/c/iir.cpp:af_iir src/api/c/rgb_gray.cpp:convert src/api/c/match_template.cpp:af_match_template src/api/c/transform.cpp:af_transform_common src/api/c/surface.cpp:af_draw_surface (also f64 missing) src/api/c/vector_field.cpp:vectorFieldWrapper src/api/c/sat.cpp:af_sat src/api/c/harris.cpp:af_harris src/api/c/plot.cpp:plotWrapper src/api/c/ycbcr_rgb.cpp:convert

christophe-murphy avatar Jun 05 '24 20:06 christophe-murphy