awkward icon indicating copy to clipboard operation
awkward copied to clipboard

[CPU/GPU] prod kernel on an empty list of a complex type gives a wrong result

Open ianna opened this issue 1 year ago • 0 comments

Version of Awkward Array

master branch (2.6.7)

Description and code to reproduce

def test_block_boundary_prod_complex13():
    rng = np.random.default_rng(seed=42)
    array = rng.integers(50, size=1000)
    complex_array = np.vectorize(complex)(
        array[0 : len(array) : 2], array[1 : len(array) : 2]
    )
    content = ak.contents.NumpyArray(complex_array)
    
    assert np.allclose(to_list(ak.prod(content, -1, highlevel=False)), np.prod(ak.Array(content)), equal_nan=True)

    offsets = ak.index.Index64(np.array([0, 5, 996, 1000], dtype=np.int64))
    depth1 = ak.contents.ListOffsetArray(offsets, content)
    print(to_list(ak.prod(depth1, -1, highlevel=False))) 
    print([np.prod(ak.Array(depth1[0])), np.prod(ak.Array(depth1[1])), np.prod(ak.Array(depth1[2]))])

where ak.Array(depth1[2]) has ArrayType(NumpyType('complex128'), 0, None). The ak.prod result of an empty list should be (1+0j), as correctly produced by Numpy:

[(6891360-24365880j), (nan+nanj), 0j]
[(6891360-24365880j), (nan+nanj), (1+0j)]

ianna avatar Sep 12 '24 13:09 ianna