On Sun, 2008-05-25 at 17:27 +0200, Luc Maisonobe wrote: > Hello, > > Someone complained recently to me about poor performances of > RealMatrix.multiply(). A quick check showed me that changing the indices > checks in RealMatrix.getEntry() tremendously improved the performances > (about a 3 to 1 ratio in a simple case). > > The current implementation explicitely calls the isValidCoordinate prior > to getting the element from the underlying array. This method calls > getRowDimension and getColumnDimension and do the intervals checks. I > think this is unnecessary and duplicates the checks that are already > done by the JVM. I would like to replace this by an a posteriori check > when the JVM triggers an ArrayIndexOutOfBoundException. Basically, this > means replacing: > > if (!isValidCoordinate(row,column)) { > throw new MatrixIndexException(...); > } > return data[row][column]; > > by: > > try { > return data[row][column]; > } catch (ArrayIndexOutOfBoundsException e) { > throw new MatrixIndexException(...); > } > > > I have read somewhere that array index checking is now highly optimized > by JVM and can even be automatically removed in some cases. Do you think > moving to such a way to handle index errors is sensible ? There are > several other places where this could be done, so I would like to have > your comments before doing the changes.
Sounds good to me. I cannot think of any problems that might cause, it does seem likely to result in a performance improvement, and it looks safer. Regards, Simon --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]