public class ArrayUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
allUnique(int[] toTest)
Returns true if all of the elements in the
given int array are unique
|
static boolean |
anyLargerThan(int[] arrs,
int check) |
static boolean |
anyLess(int[] target,
int[] test) |
static boolean |
anyLessThan(int[] arrs,
int check) |
static boolean |
anyMore(int[] target,
int[] test) |
static int |
argMax(int[] in)
Returns the index of the maximum value in the array.
|
static int |
argMax(long[] in)
Returns the index of the maximum value in the array.
|
static int |
argMin(int[] in)
Returns the index of the minimum value in the array.
|
static int |
argMin(long[] in)
Returns the index of the minimum value in the array.
|
static int |
argMinOfMax(int[]... arrays) |
static int |
argMinOfMax(int[] first,
int[] second) |
static long |
argMinOfMax(long[]... arrays) |
static long |
argMinOfMax(long[] first,
long[] second) |
static int |
argMinOfSum(int[] first,
int[] second) |
static int[] |
argsort(int[] a)
Original credit: https://github.com/alberts/array4j/blob/master/src/main/java/net/lunglet/util/ArrayUtils.java
|
static int[] |
argsort(int[] a,
boolean ascending) |
static int |
arrayLength(Object current)
Calculate the length of the object or primitive array.
|
static int[] |
arrayShape(Object array)
Calculate the shape of an arbitrary multi-dimensional array.
|
static int[] |
arrayShape(Object array,
boolean allowSize0Dims)
Calculate the shape of an arbitrary multi-dimensional array.
Note that the method assumes the array is rectangular (not ragged) and first elements (i.e., array[0][0][0]...) are non-null Note also that if allowSize0Dims is true, any elements are length 0, all subsequent dimensions will be reported as 0. |
static <T> void |
assertNotRagged(T[] array)
Assert that the specified array is not ragged (i.e., is rectangular).
Can be used to check Object arrays with any number of dimensions (up to rank 4), or primitive arrays with rank 2 or higher An IllegalStateException is thrown if the array is ragged |
static void |
assertSquare(double[]... d) |
static int[] |
buildHalfVector(Random rng,
int length) |
static int[] |
buildInterleavedVector(Random rng,
int length) |
static long[] |
buildInterleavedVector(Random rng,
long length) |
static int |
calcOffset(int[] shape,
int[] offsets,
int[] strides)
Compute the offset
based on teh shape strides and offsets
|
static int |
calcOffset(List<Integer> shape,
List<Integer> offsets,
List<Integer> strides)
Compute the offset
based on teh shape strides and offsets
|
static long |
calcOffset(long[] shape,
long[] offsets,
long[] strides)
Compute the offset
based on teh shape strides and offsets
|
static long |
calcOffsetLong(int[] shape,
int[] offsets,
int[] strides)
Compute the offset
based on teh shape strides and offsets
|
static long |
calcOffsetLong(List<Integer> shape,
List<Integer> offsets,
List<Integer> strides)
Compute the offset
based on teh shape strides and offsets
|
static long |
calcOffsetLong2(List<Long> shape,
List<Long> offsets,
List<Long> strides) |
static int[] |
calcStrides(int[] shape)
Computes the standard packed array strides for a given shape.
|
static int[] |
calcStrides(int[] shape,
int startValue)
Computes the standard packed array strides for a given shape.
|
static long[] |
calcStrides(long[] shape) |
static long[] |
calcStrides(long[] shape,
int startValue)
Computes the standard packed array strides for a given shape.
|
static int[] |
calcStridesFortran(int[] shape)
Computes the standard packed array strides for a given shape.
|
static int[] |
calcStridesFortran(int[] shape,
int startNum)
Computes the standard packed array strides for a given shape.
|
static long[] |
calcStridesFortran(long[] shape) |
static long[] |
calcStridesFortran(long[] shape,
int startNum)
Computes the standard packed array strides for a given shape.
|
static <E> E[] |
combine(E[]... arrs) |
static double[] |
combine(float[]... ints)
Combines a apply of int arrays in to one flat int array
|
static int[] |
combine(int[]... ints)
Combines a apply of int arrays in to one flat int array
|
static float[] |
combine(List<float[]> nums)
Combines a apply of int arrays in to one flat int array
|
static long[] |
combine(long[]... ints)
Combines a apply of long arrays in to one flat long array
|
static double[] |
combineDouble(List<double[]> nums)
Combines a apply of int arrays in to one flat int array
|
static float[] |
combineFloat(List<float[]> nums)
Combines a applyTransformToDestination of int arrays in to one flat int array
|
static int[] |
consArray(int a,
int[] as) |
static boolean |
contains(int[] arr,
int value) |
static boolean |
contains(long[] arr,
int value) |
static boolean |
containsAnyNegative(int[] arr)
Returns true if any array elements are negative.
|
static boolean |
containsAnyNegative(long[] arr) |
static int[] |
convertNegativeIndices(int range,
int[] axes)
Convert all dimensions in the specified
axes array to be positive
based on the specified range of values
|
static String[] |
convertToString(int[] arr)
Convert a int array to a string array
|
static double[] |
copy(double[] data) |
static float[] |
copy(float[] data) |
static int[] |
copy(int[] copy) |
static long[] |
copy(long[] copy) |
static int[] |
copyOfRangeFrom(int length,
int from,
int to)
Generate an array from 0 to length
and generate take a subset
|
static byte[] |
cutBelowZero(byte[] data) |
static int[] |
cutBelowZero(int[] data) |
static long[] |
cutBelowZero(long[] data) |
static short[] |
cutBelowZero(short[] data) |
static int |
dotProduct(int[] xs,
int[] ys) |
static int |
dotProduct(List<Integer> xs,
List<Integer> ys) |
static long |
dotProductLong(int[] xs,
int[] ys) |
static long |
dotProductLong(List<Integer> xs,
List<Integer> ys) |
static long |
dotProductLong2(List<Long> xs,
List<Long> ys) |
static double[] |
doubleCopyOf(float[] data) |
static int[] |
empty() |
static boolean |
equals(float[] data,
double[] data2) |
static <T> T[] |
filterNull(T... in) |
static boolean[] |
flatten(boolean[][] arr) |
static boolean[] |
flatten(boolean[][][] arr) |
static boolean[] |
flatten(boolean[][][][] arr) |
static byte[] |
flatten(byte[][] arr) |
static byte[] |
flatten(byte[][][] arr) |
static byte[] |
flatten(byte[][][][] arr) |
static double[] |
flatten(double[][] arr)
Convert a 2darray in to a flat
array (row wise)
|
static double[] |
flatten(double[][][] arr) |
static double[] |
flatten(double[][][][] arr) |
static float[] |
flatten(float[][] arr) |
static float[] |
flatten(float[][][] arr) |
static float[] |
flatten(float[][][][] arr) |
static int[] |
flatten(int[][] arr) |
static int[] |
flatten(int[][][] arr) |
static int[] |
flatten(int[][][][] arr) |
static long[] |
flatten(long[][] arr) |
static long[] |
flatten(long[][][] arr) |
static long[] |
flatten(long[][][][] arr) |
static short[] |
flatten(short[][] arr) |
static short[] |
flatten(short[][][] arr) |
static short[] |
flatten(short[][][][] arr) |
static double[] |
flattenDoubleArray(Object doubleArray)
Convert an arbitrary-dimensional rectangular double array to flat vector.
Can pass double[], double[][], double[][][], etc. |
static double[] |
flattenF(double[][] arr)
Convert a 2darray in to a flat
array (row wise)
|
static float[] |
flattenF(float[][] arr) |
static int[] |
flattenF(int[][] arr) |
static long[] |
flattenF(long[][] arr) |
static float[] |
flattenFloatArray(Object floatArray)
Convert an arbitrary-dimensional rectangular float array to flat vector.
Can pass float[], float[][], float[][][], etc. |
static float[] |
floatCopyOf(double[] data) |
static int |
fromBoolean(boolean bool)
Convert an int
|
static short |
fromFloat(float v) |
static <T> T |
getRandomElement(List<T> list) |
static long[] |
getTensorMmulShape(long[] aShape,
long[] bShape,
int[][] axes)
Get the tensor matrix multiply shape
|
static boolean |
greaterThan(int[] target,
int[] test) |
static int[] |
invertPermutation(int... input)
Compute the inverse permutation indices for a permutation operation
Example: if input is [2, 0, 1] then output is [1, 2, 0] The idea is that x.permute(input).permute(invertPermutation(input)) == x |
static long[] |
invertPermutation(long... input) |
static boolean |
isEmptyShape(int[] shape)
Is this shape an empty shape?
Shape is considered to be an empty shape if it contains any zeros.
|
static boolean |
isEmptyShape(long[] shape)
Is this shape an empty shape?
Shape is considered to be an empty shape if it contains any zeros.
|
static boolean |
isInverse(int[] first,
int[] second)
Returns true if the given
two arrays are reverse copies of each other
|
static boolean |
isZero(int[] as)
Returns true if any of the elements are zero
|
static boolean |
isZero(long[] as) |
static int[] |
keep(int[] data,
int... index)
Return a copy of this array with only the
given index(es) remaining
|
static long[] |
keep(long[] data,
int... index)
Return a copy of this array with only the
given index(es) remaining
|
static boolean |
lessThan(int[] target,
int[] test) |
static boolean |
listOfIntsContains(List<int[]> list,
int[] target)
Proper comparison contains for list of int
arrays
|
static int |
max(int[] in)
Returns the maximum value in the array
|
static int |
min(int[] in)
Returns the minimum value in the array
|
static int[] |
mod(int[] input,
int mod) |
static void |
multiplyBy(int[] arr,
int mult)
Multiply the given array
by the given scalar
|
static int |
nonOneStride(int[] arr)
For use with row vectors to ensure consistent strides
with varying offsets
|
static int[] |
nTimes(int n,
int toReplicate)
Repeat a value n times
|
static <T> T[] |
nTimes(int n,
T toReplicate,
Class<T> tClass) |
static long[] |
nTimes(long n,
long toReplicate) |
static int[] |
of(int... arr) |
static int |
offsetFor(int[] stride,
int i)
Calculate the offset for a given stride array
|
static int[] |
permute(int[] shape,
int[] dimensions)
Permute the given input
switching the dimensions of the input shape
array with in the order of the specified
dimensions
|
static long[] |
permute(long[] shape,
int[] dimensions) |
static int[] |
plus(int[] ints,
int mult) |
static int[] |
plus(int[] ints,
int[] mult) |
static int |
prod(int... mult)
Product of an int array
|
static int |
prod(List<Integer> mult)
Product of an int array
|
static int |
prod(long... mult)
Product of an int array
|
static long |
prodLong(int... mult)
Product of an int array
|
static long |
prodLong(List<? extends Number> mult)
Product of an int array
|
static long |
prodLong(long... mult) |
static int[] |
randomPermutation(int size)
Credit to mikio braun from jblas
Create a random permutation of the numbers 0, ..., size - 1.
|
static double[] |
range(double[] data,
int to)
Returns a subset of an array from 0 to "to" (exclusive)
|
static double[] |
range(double[] data,
int to,
int stride)
Returns a subset of an array from 0 to "to" (exclusive) using the specified stride
|
static double[] |
range(double[] data,
int to,
int stride,
int numElementsEachStride)
Returns a subset of an array from 0 to "to"
using the specified stride
|
static int[] |
range(int from,
int to)
Generate an int array ranging from "from" to "to".
|
static int[] |
range(int from,
int to,
int increment)
Generate an int array ranging from "from" to "to".
|
static long[] |
range(long from,
long to) |
static long[] |
range(long from,
long to,
long increment) |
static double[] |
read(int length,
DataInputStream dis) |
static double[] |
readDouble(int length,
DataInputStream dis) |
static float[] |
readFloat(int length,
DataInputStream dis) |
static int[] |
removeIndex(int[] data,
int... index)
Return a copy of this array with the
given index omitted
PLEASE NOTE: index to be omitted must exist in source array.
|
static int[] |
removeIndex(int[] data,
int index)
Return a copy of this array with the
given index omitted
|
static Integer[] |
removeIndex(Integer[] data,
int index)
Returns the array with the item in index
removed, if the array is empty it will return the array itself
|
static long[] |
removeIndex(long[] data,
int... index) |
static long[] |
removeIndex(long[] data,
int index) |
static int[] |
replace(int[] data,
int index,
int newValue)
Return a copy of this array with the
given index omitted
|
static boolean[][] |
reshapeBoolean(boolean[] in,
int rows,
int cols) |
static boolean[][][] |
reshapeBoolean(boolean[] in,
int d0,
int d1,
int d2) |
static double[][] |
reshapeDouble(double[] in,
int rows,
int cols) |
static double[][][] |
reshapeDouble(double[] in,
int d0,
int d1,
int d2) |
static int[][] |
reshapeInt(int[] in,
int rows,
int cols) |
static int[][][] |
reshapeInt(int[] in,
int d0,
int d1,
int d2) |
static long[][] |
reshapeLong(long[] in,
int rows,
int cols) |
static long[][][] |
reshapeLong(long[] in,
int d0,
int d1,
int d2) |
static <T> T[][] |
reshapeObject(T[] in,
int rows,
int cols) |
static <T> T[][][] |
reshapeObject(T[] in,
int d0,
int d1,
int d2) |
static <E> void |
reverse(E[] e) |
static void |
reverse(int[] e)
Reverse the passed in array in place
|
static void |
reverse(long[] e) |
static <E> E[] |
reverseCopy(E[] e) |
static float[] |
reverseCopy(float[] e) |
static int[] |
reverseCopy(int[] e)
Create a backwards copy of the given array
|
static long[] |
reverseCopy(long[] e) |
static <T> void |
shuffleWithMap(List<T> objects,
int[] map) |
static <K,V extends Comparable<? super V>> |
sortMapByValue(Map<K,V> map) |
static int |
sum(int[] add)
Sum of an int array
|
static int |
sum(List<Integer> add)
Sum of an int array
|
static long |
sumLong(long... add) |
protected static <T> void |
swap(List<T> objects,
int idxA,
int idxB) |
static int[] |
times(int[] ints,
int mult) |
static int[] |
times(int[] ints,
int[] mult) |
static int[] |
toArray(List<Integer> list) |
static double[] |
toArrayDouble(List<Double> list) |
static long[] |
toArrayLong(List<Long> list) |
static short |
toBFloat16(double data) |
static short |
toBFloat16(float data) |
static short[] |
toBfloats(float[] data) |
static short[] |
toBfloats(int[] data) |
static short[] |
toBfloats(long[] data) |
static byte[] |
toByteArray(double[] doubleArray) |
static byte[] |
toByteArray(float[] doubleArray) |
static byte[] |
toByteArray(int[] intArray) |
static byte[] |
toBytes(double[] array) |
static byte[] |
toBytes(float[] array) |
static byte[] |
toBytes(int[] array) |
static byte[] |
toBytes(long[] array) |
static double[] |
toDouble(int[] data) |
static double[][] |
toDouble(int[][] arr)
Cast an int array to a double array
|
static double[] |
toDouble(long[] data) |
static double[] |
toDoubleArray(byte[] byteArray) |
static double[] |
toDoubles(float[] ints) |
static double[] |
toDoubles(int[] ints) |
static double[] |
toDoubles(int[][] ints) |
static double[] |
toDoubles(long[] ints) |
static float[] |
toFloatArray(byte[] byteArray) |
static float[] |
toFloats(double[] ints) |
static float[] |
toFloats(int[] ints) |
static float[] |
toFloats(int[][] ints) |
static float[] |
toFloats(long[] ints) |
static short |
toHalf(double data) |
static short |
toHalf(float data) |
static short[] |
toHalfs(double[] data) |
static short[] |
toHalfs(float[] data) |
static short[] |
toHalfs(int[] data) |
static short[] |
toHalfs(long[] data) |
static int[] |
toIntArray(byte[] byteArray) |
static int[] |
toInts(double[] data) |
static int[] |
toInts(float[] data) |
static int[] |
toInts(long[] array) |
static List<Integer> |
toList(int... ints) |
static long[] |
toLongArray(float[] array) |
static long[] |
toLongArray(int[] intArray) |
static long[] |
toLongs(boolean[] data) |
static long[] |
toLongs(byte[] data) |
static long[] |
toLongs(double[] data) |
static long[] |
toLongs(float[] data) |
static long[] |
toLongs(int[] data) |
static long[] |
toLongs(short[] data) |
static int[] |
toOutcomeArray(int outcome,
int numOutcomes) |
static boolean[] |
toPrimitives(Boolean[] array) |
static boolean[][] |
toPrimitives(Boolean[][] array) |
static boolean[][][] |
toPrimitives(Boolean[][][] array) |
static boolean[][][][] |
toPrimitives(Boolean[][][][] array) |
static byte[] |
toPrimitives(Byte[] array) |
static byte[][] |
toPrimitives(Byte[][] array) |
static byte[][][] |
toPrimitives(Byte[][][] array) |
static byte[][][][] |
toPrimitives(Byte[][][][] array) |
static double[] |
toPrimitives(Double[] array) |
static double[][] |
toPrimitives(Double[][] array) |
static double[][][] |
toPrimitives(Double[][][] array) |
static double[][][][] |
toPrimitives(Double[][][][] array) |
static float[] |
toPrimitives(Float[] array) |
static float[][] |
toPrimitives(Float[][] array) |
static float[][][] |
toPrimitives(Float[][][] array) |
static float[][][][] |
toPrimitives(Float[][][][] array) |
static int[] |
toPrimitives(Integer[] array) |
static int[][] |
toPrimitives(Integer[][] array) |
static int[][][] |
toPrimitives(Integer[][][] array) |
static int[][][][] |
toPrimitives(Integer[][][][] array) |
static long[] |
toPrimitives(Long[] array) |
static long[][] |
toPrimitives(Long[][] array) |
static long[][][] |
toPrimitives(Long[][][] array) |
static long[][][][] |
toPrimitives(Long[][][][] array) |
static short[] |
toPrimitives(Short[] array) |
static short[][] |
toPrimitives(Short[][] array) |
static short[][][] |
toPrimitives(Short[][][] array) |
static short[][][][] |
toPrimitives(Short[][][][] array) |
static short[] |
toShorts(double[] ints) |
static short[] |
toShorts(float[] ints) |
static short[] |
toShorts(int[] ints) |
static short[] |
toShorts(long[] ints) |
static int[] |
valueStartingAt(int valueStarting,
int[] copy,
int idxFrom,
int idxAt,
int length)
Create a copy of the given array
starting at the given index with the given length.
|
static void |
write(double[] data,
DataOutputStream dos) |
static void |
write(float[] data,
DataOutputStream dos) |
static List<double[]> |
zerosMatrix(int... dimensions) |
static List<double[]> |
zerosMatrix(long... dimensions) |
static int[][] |
zip(int[] as,
int[] bs)
Zip 2 arrays in to:
|
public static boolean containsAnyNegative(int[] arr)
arr - the array to testpublic static boolean containsAnyNegative(long[] arr)
public static boolean contains(int[] arr,
int value)
public static boolean contains(long[] arr,
int value)
public static boolean anyLargerThan(int[] arrs,
int check)
arrs - check - public static boolean anyLessThan(int[] arrs,
int check)
arrs - check - public static String[] convertToString(int[] arr)
arr - the array to convertpublic static boolean listOfIntsContains(List<int[]> list, int[] target)
list - the to searchtarget - the target int arraypublic static int[] nTimes(int n,
int toReplicate)
n - the number of times to repeattoReplicate - the value to repeatpublic static long[] nTimes(long n,
long toReplicate)
public static <T> T[] nTimes(int n,
T toReplicate,
Class<T> tClass)
public static boolean allUnique(int[] toTest)
toTest - the array to testpublic static int[] randomPermutation(int size)
public static short toBFloat16(float data)
public static short toBFloat16(double data)
public static short toHalf(float data)
public static short toHalf(double data)
public static short[] toHalfs(float[] data)
public static short[] toHalfs(int[] data)
public static short[] toHalfs(long[] data)
public static short[] toBfloats(float[] data)
public static short[] toBfloats(int[] data)
public static short[] toBfloats(long[] data)
public static long[] toLongs(byte[] data)
public static long[] toLongs(boolean[] data)
public static long[] toLongs(short[] data)
public static long[] toLongs(int[] data)
public static long[] toLongs(float[] data)
public static long[] toLongs(double[] data)
public static short[] toHalfs(double[] data)
public static short fromFloat(float v)
public static int[] toInts(float[] data)
public static int[] toInts(double[] data)
public static byte[] toBytes(int[] array)
public static byte[] toBytes(float[] array)
public static byte[] toBytes(double[] array)
public static byte[] toBytes(long[] array)
public static int[] toInts(long[] array)
public static int[] mod(int[] input,
int mod)
public static int offsetFor(int[] stride,
int i)
stride - the stride to usei - the offset to calculate forpublic static int sum(List<Integer> add)
add - the elements
to calculate the sum forpublic static int sum(int[] add)
add - the elements
to calculate the sum forpublic static long sumLong(long... add)
public static int prod(List<Integer> mult)
mult - the elements
to calculate the sum forpublic static int prod(long... mult)
mult - the elements
to calculate the sum forpublic static int prod(int... mult)
mult - the elements
to calculate the sum forpublic static long prodLong(List<? extends Number> mult)
mult - the elements
to calculate the sum forpublic static long prodLong(int... mult)
mult - the elements
to calculate the sum forpublic static long prodLong(long... mult)
public static boolean equals(float[] data,
double[] data2)
public static int[] consArray(int a,
int[] as)
public static boolean isZero(int[] as)
as - public static boolean isZero(long[] as)
public static boolean anyMore(int[] target,
int[] test)
public static boolean anyLess(int[] target,
int[] test)
public static boolean lessThan(int[] target,
int[] test)
public static boolean greaterThan(int[] target,
int[] test)
public static int calcOffset(List<Integer> shape, List<Integer> offsets, List<Integer> strides)
shape - the shape to computeoffsets - the offsets to computestrides - the strides to computepublic static int calcOffset(int[] shape,
int[] offsets,
int[] strides)
shape - the shape to computeoffsets - the offsets to computestrides - the strides to computepublic static long calcOffset(long[] shape,
long[] offsets,
long[] strides)
shape - the shape to computeoffsets - the offsets to computestrides - the strides to computepublic static long calcOffsetLong(List<Integer> shape, List<Integer> offsets, List<Integer> strides)
shape - the shape to computeoffsets - the offsets to computestrides - the strides to computepublic static long calcOffsetLong2(List<Long> shape, List<Long> offsets, List<Long> strides)
public static long calcOffsetLong(int[] shape,
int[] offsets,
int[] strides)
shape - the shape to computeoffsets - the offsets to computestrides - the strides to computepublic static int dotProduct(List<Integer> xs, List<Integer> ys)
xs - ys - public static int dotProduct(int[] xs,
int[] ys)
xs - ys - public static long dotProductLong(List<Integer> xs, List<Integer> ys)
xs - ys - public static long dotProductLong2(List<Long> xs, List<Long> ys)
xs - ys - public static long dotProductLong(int[] xs,
int[] ys)
xs - ys - public static int[] empty()
public static int[] of(int... arr)
public static int[] copy(int[] copy)
public static long[] copy(long[] copy)
public static double[] doubleCopyOf(float[] data)
public static float[] floatCopyOf(double[] data)
public static double[] range(double[] data,
int to)
data - the data to getFromOrigin a subset ofto - the end point of the datapublic static double[] range(double[] data,
int to,
int stride)
data - the data to getFromOrigin a subset ofto - the end point of the datastride - the stride to go through the arraypublic static double[] range(double[] data,
int to,
int stride,
int numElementsEachStride)
data - the data to getFromOrigin a subset ofto - the end point of the datastride - the stride to go through the arraynumElementsEachStride - the number of elements to collect at each stridepublic static int[] range(int from,
int to,
int increment)
from - the fromto - the end point of the dataincrement - the amount to increment bypublic static long[] range(long from,
long to,
long increment)
public static int[] range(int from,
int to)
from - the fromto - the end point of the datapublic static long[] range(long from,
long to)
public static double[] toDoubles(int[] ints)
public static double[] toDoubles(long[] ints)
public static double[] toDoubles(float[] ints)
public static float[] toFloats(int[][] ints)
public static double[] toDoubles(int[][] ints)
public static short[] toShorts(long[] ints)
public static short[] toShorts(int[] ints)
public static short[] toShorts(float[] ints)
public static short[] toShorts(double[] ints)
public static float[] toFloats(int[] ints)
public static float[] toFloats(long[] ints)
public static float[] toFloats(double[] ints)
public static int[] cutBelowZero(int[] data)
public static long[] cutBelowZero(long[] data)
public static short[] cutBelowZero(short[] data)
public static byte[] cutBelowZero(byte[] data)
public static int[] replace(int[] data,
int index,
int newValue)
data - the data to copyindex - the index of the item to removenewValue - the newValue to replacepublic static int[] keep(int[] data,
int... index)
data - the data to copyindex - the index of the item to removepublic static long[] keep(long[] data,
int... index)
data - the data to copyindex - the index of the item to removepublic static int[] removeIndex(int[] data,
int... index)
data - the data to copyindex - the index of the item to removepublic static long[] removeIndex(long[] data,
int... index)
public static int[][] zip(int[] as,
int[] bs)
as - bs - public static long[] getTensorMmulShape(long[] aShape,
long[] bShape,
int[][] axes)
aShape - the shape of the first arraybShape - the shape of the second arrayaxes - the axes to do the multiplypublic static int[] permute(int[] shape,
int[] dimensions)
shape - the shape to permutedimensions - the dimensionspublic static long[] permute(long[] shape,
int[] dimensions)
public static int[] argsort(int[] a)
a - public static int[] argsort(int[] a,
boolean ascending)
a - ascending - public static int[] convertNegativeIndices(int range,
int[] axes)
range - axes - public static int[] copyOfRangeFrom(int length,
int from,
int to)
length - the length to generate tofrom - the begin of the interval to taketo - the end of the interval to takepublic static byte[] toByteArray(double[] doubleArray)
doubleArray - public static double[] toDoubleArray(byte[] byteArray)
byteArray - public static byte[] toByteArray(float[] doubleArray)
doubleArray - public static long[] toLongArray(int[] intArray)
public static long[] toLongArray(float[] array)
public static float[] toFloatArray(byte[] byteArray)
byteArray - public static byte[] toByteArray(int[] intArray)
intArray - public static int[] toIntArray(byte[] byteArray)
byteArray - public static int[] removeIndex(int[] data,
int index)
data - the data to copyindex - the index of the item to removepublic static long[] removeIndex(long[] data,
int index)
public static int[] valueStartingAt(int valueStarting,
int[] copy,
int idxFrom,
int idxAt,
int length)
valueStarting - the starting valuecopy - the array to copyidxFrom - the index to start at in the from arrayidxAt - the index to start at in the return arraylength - the length of the array to createpublic static Integer[] removeIndex(Integer[] data, int index)
data - the data to remove data fromindex - the index of the item to removepublic static int[] calcStridesFortran(int[] shape,
int startNum)
shape - the shape of a matrix:startNum - the start number for the stridespublic static long[] calcStridesFortran(long[] shape,
int startNum)
shape - the shape of a matrix:startNum - the start number for the stridespublic static int[] calcStridesFortran(int[] shape)
shape - the shape of a matrix:public static long[] calcStridesFortran(long[] shape)
public static int[] calcStrides(int[] shape,
int startValue)
shape - the shape of a matrix:startValue - the startValue for the stridespublic static long[] calcStrides(long[] shape,
int startValue)
shape - the shape of a matrix:startValue - the startValue for the stridespublic static boolean isInverse(int[] first,
int[] second)
first - second - public static int[] plus(int[] ints,
int mult)
public static int[] plus(int[] ints,
int[] mult)
public static int[] times(int[] ints,
int mult)
public static int[] times(int[] ints,
int[] mult)
public static int nonOneStride(int[] arr)
arr - the array to get the stride forpublic static int[] calcStrides(int[] shape)
shape - the shape of a matrix:public static long[] calcStrides(long[] shape)
public static int[] reverseCopy(int[] e)
e - the array to createComplex a reverse clone ofpublic static long[] reverseCopy(long[] e)
public static double[] read(int length,
DataInputStream dis)
throws IOException
IOExceptionpublic static void write(double[] data,
DataOutputStream dos)
throws IOException
IOExceptionpublic static double[] readDouble(int length,
DataInputStream dis)
throws IOException
IOExceptionpublic static float[] readFloat(int length,
DataInputStream dis)
throws IOException
IOExceptionpublic static void write(float[] data,
DataOutputStream dos)
throws IOException
IOExceptionpublic static void assertSquare(double[]... d)
public static void multiplyBy(int[] arr,
int mult)
arr - the array to multilymult - the scalar to multiply bypublic static void reverse(int[] e)
e - the array to reversepublic static void reverse(long[] e)
public static List<double[]> zerosMatrix(long... dimensions)
public static List<double[]> zerosMatrix(int... dimensions)
public static float[] reverseCopy(float[] e)
public static <E> E[] reverseCopy(E[] e)
public static <E> void reverse(E[] e)
public static boolean[] flatten(boolean[][] arr)
public static boolean[] flatten(boolean[][][] arr)
public static float[] flatten(float[][] arr)
public static float[] flatten(float[][][] arr)
public static double[] flatten(double[][][] arr)
public static int[] flatten(int[][][] arr)
public static short[] flatten(short[][][] arr)
public static byte[] flatten(byte[][][] arr)
public static long[] flatten(long[][][][] arr)
public static short[] flatten(short[][][][] arr)
public static byte[] flatten(byte[][][][] arr)
public static boolean[] flatten(boolean[][][][] arr)
public static float[] flatten(float[][][][] arr)
public static double[] flatten(double[][][][] arr)
public static int[] flatten(int[][][][] arr)
public static int[] flatten(int[][] arr)
public static short[] flatten(short[][] arr)
public static byte[] flatten(byte[][] arr)
public static long[] flatten(long[][] arr)
public static long[] flatten(long[][][] arr)
public static double[] flatten(double[][] arr)
arr - the array to flattenpublic static double[] flattenF(double[][] arr)
arr - the array to flattenpublic static float[] flattenF(float[][] arr)
public static int[] flattenF(int[][] arr)
public static long[] flattenF(long[][] arr)
public static int[][] reshapeInt(int[] in,
int rows,
int cols)
public static int[][][] reshapeInt(int[] in,
int d0,
int d1,
int d2)
public static double[][] reshapeDouble(double[] in,
int rows,
int cols)
public static double[][][] reshapeDouble(double[] in,
int d0,
int d1,
int d2)
public static long[][] reshapeLong(long[] in,
int rows,
int cols)
public static long[][][] reshapeLong(long[] in,
int d0,
int d1,
int d2)
public static boolean[][] reshapeBoolean(boolean[] in,
int rows,
int cols)
public static boolean[][][] reshapeBoolean(boolean[] in,
int d0,
int d1,
int d2)
public static <T> T[][] reshapeObject(T[] in,
int rows,
int cols)
public static <T> T[][][] reshapeObject(T[] in,
int d0,
int d1,
int d2)
public static double[][] toDouble(int[][] arr)
arr - the array to castpublic static float[] combineFloat(List<float[]> nums)
nums - the int arrays to combineDoublepublic static float[] combine(List<float[]> nums)
nums - the int arrays to combineDoublepublic static double[] combineDouble(List<double[]> nums)
nums - the int arrays to combineDoublepublic static double[] combine(float[]... ints)
ints - the int arrays to combineDoublepublic static int[] combine(int[]... ints)
ints - the int arrays to combineDoublepublic static long[] combine(long[]... ints)
ints - the int arrays to combineDoublepublic static <E> E[] combine(E[]... arrs)
public static int[] toOutcomeArray(int outcome,
int numOutcomes)
public static double[] toDouble(int[] data)
public static double[] toDouble(long[] data)
public static float[] copy(float[] data)
public static double[] copy(double[] data)
public static double[] flattenDoubleArray(Object doubleArray)
public static float[] flattenFloatArray(Object floatArray)
public static int[] arrayShape(Object array)
public static int[] arrayShape(Object array, boolean allowSize0Dims)
public static int max(int[] in)
public static int min(int[] in)
public static int argMax(int[] in)
public static int argMin(int[] in)
public static int argMax(long[] in)
public static int argMin(long[] in)
public static int[] buildHalfVector(Random rng, int length)
public static int[] buildInterleavedVector(Random rng, int length)
public static long[] buildInterleavedVector(Random rng, long length)
protected static <T> void swap(List<T> objects, int idxA, int idxB)
public static <T> void shuffleWithMap(List<T> objects, int[] map)
public static int argMinOfMax(int[] first,
int[] second)
public static long argMinOfMax(long[] first,
long[] second)
public static int argMinOfMax(int[]... arrays)
public static long argMinOfMax(long[]... arrays)
public static int argMinOfSum(int[] first,
int[] second)
public static <K,V extends Comparable<? super V>> Map<K,V> sortMapByValue(Map<K,V> map)
public static <T> T getRandomElement(List<T> list)
public static int fromBoolean(boolean bool)
bool - public static long[] toPrimitives(Long[] array)
public static int[] toPrimitives(Integer[] array)
public static short[] toPrimitives(Short[] array)
public static byte[] toPrimitives(Byte[] array)
public static float[] toPrimitives(Float[] array)
public static double[] toPrimitives(Double[] array)
public static boolean[] toPrimitives(Boolean[] array)
public static long[][] toPrimitives(Long[][] array)
public static int[][] toPrimitives(Integer[][] array)
public static short[][] toPrimitives(Short[][] array)
public static byte[][] toPrimitives(Byte[][] array)
public static double[][] toPrimitives(Double[][] array)
public static float[][] toPrimitives(Float[][] array)
public static boolean[][] toPrimitives(Boolean[][] array)
public static long[][][] toPrimitives(Long[][][] array)
public static int[][][] toPrimitives(Integer[][][] array)
public static short[][][] toPrimitives(Short[][][] array)
public static byte[][][] toPrimitives(Byte[][][] array)
public static double[][][] toPrimitives(Double[][][] array)
public static float[][][] toPrimitives(Float[][][] array)
public static boolean[][][] toPrimitives(Boolean[][][] array)
public static long[][][][] toPrimitives(Long[][][][] array)
public static int[][][][] toPrimitives(Integer[][][][] array)
public static short[][][][] toPrimitives(Short[][][][] array)
public static byte[][][][] toPrimitives(Byte[][][][] array)
public static double[][][][] toPrimitives(Double[][][][] array)
public static float[][][][] toPrimitives(Float[][][][] array)
public static boolean[][][][] toPrimitives(Boolean[][][][] array)
public static <T> void assertNotRagged(T[] array)
array - Array to checkpublic static int arrayLength(Object current)
current - public static int[] invertPermutation(int... input)
input - 1D indices for permutationpublic static long[] invertPermutation(long... input)
input - 1D indices for permutationinvertPermutation(int...)public static boolean isEmptyShape(long[] shape)
shape - Shape to checkpublic static boolean isEmptyShape(int[] shape)
shape - Shape to checkpublic static <T> T[] filterNull(T... in)
Copyright © 2021. All rights reserved.