You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/12/17 01:35:53 UTC
[commons-math] 03/04: Removed obsolete "copyOf" method.
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 6e5577ad8adff3aad503365a3e118453501bcfef
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Dec 17 02:18:44 2019 +0100
Removed obsolete "copyOf" method.
---
.../org/apache/commons/math4/util/MathArrays.java | 65 -----------
.../apache/commons/math4/util/MathArraysTest.java | 128 +--------------------
2 files changed, 1 insertion(+), 192 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/util/MathArrays.java b/src/main/java/org/apache/commons/math4/util/MathArrays.java
index 0f7046e..a7488e2 100644
--- a/src/main/java/org/apache/commons/math4/util/MathArrays.java
+++ b/src/main/java/org/apache/commons/math4/util/MathArrays.java
@@ -766,71 +766,6 @@ public class MathArrays {
}
/**
- * Creates a copy of the {@code source} array.
- *
- * @param source Array to be copied.
- * @return the copied array.
- */
- public static int[] copyOf(int[] source) {
- return copyOf(source, source.length);
- }
-
- /**
- * Creates a copy of the {@code source} array.
- *
- * @param source Array to be copied.
- * @return the copied array.
- */
- public static double[] copyOf(double[] source) {
- return copyOf(source, source.length);
- }
-
- /**
- * Creates a copy of the {@code source} array.
- *
- * @param source Array to be copied.
- * @param len Number of entries to copy. If smaller then the source
- * length, the copy will be truncated, if larger it will padded with
- * zeroes.
- * @return the copied array.
- */
- public static int[] copyOf(int[] source, int len) {
- final int[] output = new int[len];
- System.arraycopy(source, 0, output, 0, FastMath.min(len, source.length));
- return output;
- }
-
- /**
- * Creates a copy of the {@code source} array.
- *
- * @param source Array to be copied.
- * @param len Number of entries to copy. If smaller then the source
- * length, the copy will be truncated, if larger it will padded with
- * zeroes.
- * @return the copied array.
- */
- public static double[] copyOf(double[] source, int len) {
- final double[] output = new double[len];
- System.arraycopy(source, 0, output, 0, FastMath.min(len, source.length));
- return output;
- }
-
- /**
- * Creates a copy of the {@code source} array.
- *
- * @param source Array to be copied.
- * @param from Initial index of the range to be copied, inclusive.
- * @param to Final index of the range to be copied, exclusive. (This index may lie outside the array.)
- * @return the copied array.
- */
- public static double[] copyOfRange(double[] source, int from, int to) {
- final int len = to - from;
- final double[] output = new double[len];
- System.arraycopy(source, from, output, 0, FastMath.min(len, source.length - from));
- return output;
- }
-
- /**
* Returns true iff both arguments are null or have same dimensions and all
* their elements are equal as defined by
* {@link Precision#equals(float,float)}.
diff --git a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
index f4a5e6c..87ab07e 100644
--- a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
+++ b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
@@ -48,7 +48,7 @@ public class MathArraysTest {
@Test
public void testScale() {
final double[] test = new double[] { -2.5, -1, 0, 1, 2.5 };
- final double[] correctTest = MathArrays.copyOf(test);
+ final double[] correctTest = Arrays.copyOf(test, test.length);
final double[] correctScaled = new double[]{5.25, 2.1, 0, -2.1, -5.25};
final double[] scaled = MathArrays.scale(-2.1, test);
@@ -543,132 +543,6 @@ public class MathArraysTest {
}
@Test
- public void testCopyOfInt() {
- final int[] source = { Integer.MIN_VALUE,
- -1, 0, 1, 3, 113, 4769,
- Integer.MAX_VALUE };
- final int[] dest = MathArrays.copyOf(source);
-
- Assert.assertEquals(dest.length, source.length);
- for (int i = 0; i < source.length; i++) {
- Assert.assertEquals(source[i], dest[i]);
- }
- }
-
- @Test
- public void testCopyOfInt2() {
- final int[] source = { Integer.MIN_VALUE,
- -1, 0, 1, 3, 113, 4769,
- Integer.MAX_VALUE };
- final int offset = 3;
- final int[] dest = MathArrays.copyOf(source, source.length - offset);
-
- Assert.assertEquals(dest.length, source.length - offset);
- for (int i = 0; i < source.length - offset; i++) {
- Assert.assertEquals(source[i], dest[i]);
- }
- }
-
- @Test
- public void testCopyOfInt3() {
- final int[] source = { Integer.MIN_VALUE,
- -1, 0, 1, 3, 113, 4769,
- Integer.MAX_VALUE };
- final int offset = 3;
- final int[] dest = MathArrays.copyOf(source, source.length + offset);
-
- Assert.assertEquals(dest.length, source.length + offset);
- for (int i = 0; i < source.length; i++) {
- Assert.assertEquals(source[i], dest[i]);
- }
- for (int i = source.length; i < source.length + offset; i++) {
- Assert.assertEquals(0, dest[i], 0);
- }
- }
-
- @Test
- public void testCopyOfDouble() {
- final double[] source = { Double.NEGATIVE_INFINITY,
- -Double.MAX_VALUE,
- -1, 0,
- Double.MIN_VALUE,
- FastMath.ulp(1d),
- 1, 3, 113, 4769,
- Double.MAX_VALUE,
- Double.POSITIVE_INFINITY };
- final double[] dest = MathArrays.copyOf(source);
-
- Assert.assertEquals(dest.length, source.length);
- for (int i = 0; i < source.length; i++) {
- Assert.assertEquals(source[i], dest[i], 0);
- }
- }
-
- @Test
- public void testCopyOfDouble2() {
- final double[] source = { Double.NEGATIVE_INFINITY,
- -Double.MAX_VALUE,
- -1, 0,
- Double.MIN_VALUE,
- FastMath.ulp(1d),
- 1, 3, 113, 4769,
- Double.MAX_VALUE,
- Double.POSITIVE_INFINITY };
- final int offset = 3;
- final double[] dest = MathArrays.copyOf(source, source.length - offset);
-
- Assert.assertEquals(dest.length, source.length - offset);
- for (int i = 0; i < source.length - offset; i++) {
- Assert.assertEquals(source[i], dest[i], 0);
- }
- }
-
- @Test
- public void testCopyOfDouble3() {
- final double[] source = { Double.NEGATIVE_INFINITY,
- -Double.MAX_VALUE,
- -1, 0,
- Double.MIN_VALUE,
- FastMath.ulp(1d),
- 1, 3, 113, 4769,
- Double.MAX_VALUE,
- Double.POSITIVE_INFINITY };
- final int offset = 3;
- final double[] dest = MathArrays.copyOf(source, source.length + offset);
-
- Assert.assertEquals(dest.length, source.length + offset);
- for (int i = 0; i < source.length; i++) {
- Assert.assertEquals(source[i], dest[i], 0);
- }
- for (int i = source.length; i < source.length + offset; i++) {
- Assert.assertEquals(0, dest[i], 0);
- }
- }
-
- @Test
- public void testCopyOfRange() {
- final double[] source = { Double.NEGATIVE_INFINITY,
- -Double.MAX_VALUE,
- -1, 0,
- Double.MIN_VALUE,
- FastMath.ulp(1d),
- 1, 3, 113, 4769,
- Double.MAX_VALUE,
- Double.POSITIVE_INFINITY };
- final int from = 3;
- final int to = source.length + 14;
- final double[] dest = MathArrays.copyOfRange(source, from, to);
-
- Assert.assertEquals(dest.length, to - from);
- for (int i = from; i < source.length; i++) {
- Assert.assertEquals(source[i], dest[i - from], 0);
- }
- for (int i = source.length; i < dest.length; i++) {
- Assert.assertEquals(0, dest[i - from], 0);
- }
- }
-
- @Test
public void testArrayEquals() {
Assert.assertFalse(MathArrays.equals(new double[] { 1d }, null));
Assert.assertFalse(MathArrays.equals(null, new double[] { 1d }));