NdArray implementations don't throw IllegalRankException as documented if no coordinates provided
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 928
- Forks
- 227
- PR merge metrics
- No merged PRs in 30d
Description
Instead, when no coordinates are provided, we return the scalar at (0, 0, ...). Is this an important idiom that we are preserving, or a questionable choice, or simply a bug?
Here's an example of an abstract method of FloatNdArray that is documented to throw IllegalRankException:
/**
* Returns the float value of the scalar found at the given coordinates.
*
* . . .
*
* @param coordinates coordinates of the scalar to resolve
* @return value of that scalar
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
*/
float getFloat(long... coordinates);
Here's the implementation in FloatDenseNdArray:
@Override
public float getFloat(long... indices) {
return buffer.getFloat(positionOf(indices, true));
}
But if indices.length == 0, then positionOf does not throw the claimed IllegalRankException:
long positionOf(long[] coords, boolean isValue) {
if (coords == null || coords.length == 0) {
return 0;
}
Validator.coordinates(dimensions, coords, isValue);
return dimensions.positionOf(coords);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the documented FloatNdArray.getFloat contract and compare it with FloatDenseNdArray.getFloat and positionOf, especially the zero-coordinate branch. Determine whether returning the scalar at position 0 is intended or violates the documented exception behavior; done means the behavior and its documentation agree, with relevant coverage added or updated if the project provides it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100