From 937d4feabc5b72b1d41768f23f665ef99d1d4131 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 4 Jan 2009 12:09:53 +0000 Subject: [PATCH] avoid ugly call to getDataRef that relies on vector internal implementation git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@731232 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math/linear/DenseRealMatrix.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/commons/math/linear/DenseRealMatrix.java b/src/java/org/apache/commons/math/linear/DenseRealMatrix.java index 418856480..7ff95bfe0 100644 --- a/src/java/org/apache/commons/math/linear/DenseRealMatrix.java +++ b/src/java/org/apache/commons/math/linear/DenseRealMatrix.java @@ -1032,13 +1032,12 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable throws MatrixIndexException { checkRowIndex(row); - final RealVectorImpl out = new RealVectorImpl(columns); + final double[] outData = new double[columns]; // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; - double[] outData = out.getDataRef(); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; @@ -1046,7 +1045,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable outIndex += jWidth; } - return out; + return new RealVectorImpl(outData, false); } @@ -1065,14 +1064,13 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable throws MatrixIndexException { checkColumnIndex(column); - final RealVectorImpl out = new RealVectorImpl(rows); + final double[] outData = new double[rows]; // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outIndex = 0; - double[] outData = out.getDataRef(); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; @@ -1081,7 +1079,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable } } - return out; + return new RealVectorImpl(outData, false); }