Skip to content

Numpy Interoperability Issues with certain datatypes #92

Closed
@lukasbindreiter

Description

@lukasbindreiter

There appears to be some issue regarding the interoperability between numpy and arrayfire-python regarding certain data types.
I did the conversion using the methods:

# numpy to arrayfire
af.interop.np_to_af_array

# arrayfire to numpy
af.Array.__array__()

The only two data types which appear to work as intended are float and double (f32 and f64 in Arrayfire, np.float32 and np.float64 in numpy).

64 bit integer values (signed and unsigned) and bool appear to be not supported (KeyError when trying to convert), but the data types u8, u32 and s32 are not converted correctly.

An example:

nparr = np.array([5, 10, 15, 20, 25, 30], np.int)
print(nparr)
# Output: [ 5 10 15 20 25 30]

afarr = af.interop.np_to_af_array(nparr)
print(afarr)
# Output:
# arrayfire.Array()
# Type: long int
# [6 1 1 1]
#42949672965 
#85899345935 
#128849018905 
# -7780732514909268839 
#0
#0

afarr += 10
print(afarr.__array__())
# Output: [25 10 35 20 45 30] instead of [25, 30, 35, 40, 45, 50]
# Ten was only added to every second value!

I tried these conversions with all of the aforementioned datatypes

I am using ArrayFire v3.3.2 (build f65dd97) with Python 3.5.2 on 64bit Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions