Skip to content

[BUG] ndarray_from_mp_obj() doesn't support upper half of uint16 #723

Closed
@sfe-SparkFro

Description

@sfe-SparkFro

Describe the bug

Similar to #722 but a bit different, so making a separate issue.

if((ivalue < -32767) || (ivalue > 32767)) {
// the integer value clearly does not fit the ulab integer types, so move on to float
ndarray = ndarray_new_linear_array(1, NDARRAY_FLOAT);
mp_float_t *array = (mp_float_t *)ndarray->array;
array[0] = (mp_float_t)ivalue;
} else {

ivalue > 32767 should be ivalue > 65535

ulab version: 6.7.4-4D-c

To Reproduce

from ulab import numpy as np
foo = np.ones((1), dtype=np.uint16) * 65535
print(foo)

Expected behavior

Should print:

array([65535], dtype=uint16)

Instead prints:

array([65535.0], dtype=float32)

It incorrectly promotes the dtype to float.

Additional context

Testing on my end, making the suggested change fixes the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions