Skip to content

Restrictive Data Type in NDArray Constructor #12

@ershadow786

Description

@ershadow786

This issue addresses the use of a fixed data type (int) in the constructor of the NDArray class. Here's a breakdown of the concern.

Concern:

The current implementation creates an array of type int regardless of the actual data type held by the T generic parameter. This limits flexibility and might not be suitable for scenarios where other data types (e.g., float, double) are needed.

While writing test cases for the NDArray class, specifically the testAddition method, an error arises due to the constructor's use of int.class. This implementation restricts the NDArray class to only support integer arrays, which causes issues when trying to create NDArray instances for other data types like Integer[][].

In the test case below, the use of numJ.array(data1) and numJ.array(data2) leads to an error because the constructor is unable to handle the generic type:

@Test
void testAddition() throws Exception {
    Integer[][] data1 = {{1, 2}, {3, 4}};
    Integer[][] data2 = {{5, 6}, {7, 8}};
    NDArray<Integer[][]> arr1 = numJ.array(data1);
    NDArray<Integer[][]> arr2 = numJ.array(data2);
    NDArray<Integer> result = numJ.add(arr1, arr2);
    assertArrayEquals(new Integer[][]{{6, 8}, {10, 12}}, (Integer[][]) result.getArray());
}

image

Metadata

Metadata

Assignees

Labels

2. Array CreationSub task of the task Array creationResolvedbugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status
Resolved Issues

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions