static double[] linearlyShortenArray(double[] a, int newLength) { int l = l(a); if (newLength == l) ret a; double[] b = new[newLength]; double x = 0, step = doubleRatio(newLength, l); for i to newLength: { b[i] = a[iround(x)]; x += step; } ret b; } static short[] linearlyShortenArray(short[] a, int newLength) { int l = l(a); if (newLength == l) ret a; short[] b = new[newLength]; double x = 0, step = doubleRatio(newLength, l); for i to newLength: { b[i] = a[iround(x)]; x += step; } ret b; }