J-Libraries / numJ

Java library to fulfil the requirement of numpy in java
https://j-libraries.github.io/numJ/
Apache License 2.0
21 stars 4 forks source link

IllegalArgumentException: argument type mismatch in NDArray flattenRecursive Method #15

Open ershadow786 opened 1 month ago

ershadow786 commented 1 month ago

Issue Description:

The NDArray.flatten() method throws an IllegalArgumentException: argument type mismatch during execution. This occurs when attempting to flatten a multidimensional array of a certain type. The error originates from trying to set elements in the array via reflection in the Array.set() method.

The issue was encountered in the following test case:

@Test
void testFlatten() {
    // Test case setup with a multidimensional array
    NDArray<T> ndArray = numJ.array(new Integer[][]{{1, 2}, {3, 4}});
    NDArray<T> flattened = ndArray.flatten();

    // Assertions
    assertArrayEquals(new Integer[]{1, 2, 3, 4}, (Integer[]) flattened.getArray());
}

The stack trace points to a type mismatch error in the flattenRecursive() method:

java.lang.IllegalArgumentException: argument type mismatch
    at java.base/java.lang.reflect.Array.set(Native Method)
    at com.library.numj.NDArray.flattenRecursive(NDArray.java:264)
    ...