code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
844 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public static boolean anyLessThan(int[] arrs, int check) { for(int i = 0; i < arrs.length; i++) { if(arrs[i] < check) return true; } return false; }
@param arrs @param check @return
ArrayUtil::anyLessThan
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static String[] convertToString(int[] arr) { Preconditions.checkNotNull(arr); String[] ret = new String[arr.length]; for(int i = 0; i < arr.length; i++) { ret[i] = String.valueOf(arr[i]); } return ret; }
Convert a int array to a string array @param arr the array to convert @return the equivalent string array
ArrayUtil::convertToString
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static boolean listOfIntsContains(List<int[]> list,int[] target) { for(int[] arr : list) if(Arrays.equals(target,arr)) return true; return false; }
Proper comparison contains for list of int arrays @param list the to search @param target the target int array @return whether the given target array is contained in the list
ArrayUtil::listOfIntsContains
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] nTimes(int n, int toReplicate) { int[] ret = new int[n]; Arrays.fill(ret, toReplicate); return ret; }
Repeat a value n times @param n the number of times to repeat @param toReplicate the value to repeat @return an array of length n filled with the given value
ArrayUtil::nTimes
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static boolean allUnique(int[] toTest) { Set<Integer> set = new HashSet<>(); for (int i : toTest) { if (!set.contains(i)) set.add(i); else return false; } return true; }
Returns true if all the elements in the given int array are unique @param toTest the array to test @return true if all the items are unique false otherwise
ArrayUtil::allUnique
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] randomPermutation(int size) { Random r = new Random(); int[] result = new int[size]; for (int j = 0; j < size; j++) { result[j] = j + 1; } for (int j = size - 1; j > 0; j--) { int k = r.nextInt(j); int temp = result[j]; result[j] = result[k]; result[k] = temp; } return result; }
Credit to mikio braun from jblas <p> Create a random permutation of the numbers 0, ..., size - 1. </p> see Algorithm P, D.E. Knuth: The Art of Computer Programming, Vol. 2, p. 145
ArrayUtil::randomPermutation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int offsetFor(int[] stride, int i) { int ret = 0; for (int j = 0; j < stride.length; j++) ret += (i * stride[j]); return ret; }
Calculate the offset for a given stride array @param stride the stride to use @param i the offset to calculate for @return the offset for the given stride
ArrayUtil::offsetFor
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int sum(List<Integer> add) { if (add.isEmpty()) return 0; int ret = 0; for (int i = 0; i < add.size(); i++) ret += add.get(i); return ret; }
Sum of an int array @param add the elements to calculate the sum for @return the sum of this array
ArrayUtil::sum
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int sum(int[] add) { if (add.length < 1) return 0; int ret = 0; for (int i = 0; i < add.length; i++) ret += add[i]; return ret; }
Sum of an int array @param add the elements to calculate the sum for @return the sum of this array
ArrayUtil::sum
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int prod(List<Integer> mult) { if (mult.isEmpty()) return 0; int ret = 1; for (int i = 0; i < mult.size(); i++) ret *= mult.get(i); return ret; }
Product of an int array @param mult the elements to calculate the sum for @return the product of this array
ArrayUtil::prod
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int prod(long... mult) { if (mult.length < 1) return 0; int ret = 1; for (int i = 0; i < mult.length; i++) ret *= mult[i]; return ret; }
Product of an int array @param mult the elements to calculate the sum for @return the product of this array
ArrayUtil::prod
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int prod(int... mult) { if (mult.length < 1) return 0; int ret = 1; for (int i = 0; i < mult.length; i++) ret *= mult[i]; return ret; }
Product of an int array @param mult the elements to calculate the sum for @return the product of this array
ArrayUtil::prod
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long prodLong(List<? extends Number> mult) { if (mult.isEmpty()) return 0; long ret = 1; for (int i = 0; i < mult.size(); i++) ret *= mult.get(i).longValue(); return ret; }
Product of an int array @param mult the elements to calculate the sum for @return the product of this array
ArrayUtil::prodLong
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long prodLong(int... mult) { if (mult.length < 1) return 0; long ret = 1; for (int i = 0; i < mult.length; i++) ret *= mult[i]; return ret; }
Product of an int array @param mult the elements to calculate the sum for @return the product of this array
ArrayUtil::prodLong
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static boolean isZero(int[] as) { for (int i = 0; i < as.length; i++) { if (as[i] == 0) return true; } return false; }
Returns true if any of the elements are zero @param as @return
ArrayUtil::isZero
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int calcOffset(List<Integer> shape, List<Integer> offsets, List<Integer> strides) { if (shape.size() != offsets.size() || shape.size() != strides.size()) throw new IllegalArgumentException("Shapes,strides, and offsets must be the same size"); int ret = 0; for (int i = 0; i < offsets.size(); i++) { //we should only do this in the general case, not on vectors //the reason for this is we force everything including scalars //to be 2d if (shape.get(i) == 1 && offsets.size() > 2 && i > 0) continue; ret += offsets.get(i) * strides.get(i); } return ret; }
Compute the offset based on teh shape strides and offsets @param shape the shape to compute @param offsets the offsets to compute @param strides the strides to compute @return the offset for the given shape,offset,and strides
ArrayUtil::calcOffset
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int calcOffset(int[] shape, int[] offsets, int[] strides) { if (shape.length != offsets.length || shape.length != strides.length) throw new IllegalArgumentException("Shapes,strides, and offsets must be the same size"); int ret = 0; for (int i = 0; i < offsets.length; i++) { if (shape[i] == 1) continue; ret += offsets[i] * strides[i]; } return ret; }
Compute the offset based on teh shape strides and offsets @param shape the shape to compute @param offsets the offsets to compute @param strides the strides to compute @return the offset for the given shape,offset,and strides
ArrayUtil::calcOffset
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long calcOffset(long[] shape, long[] offsets, long[] strides) { if (shape.length != offsets.length || shape.length != strides.length) throw new IllegalArgumentException("Shapes,strides, and offsets must be the same size"); long ret = 0; for (int i = 0; i < offsets.length; i++) { if (shape[i] == 1) continue; ret += offsets[i] * strides[i]; } return ret; }
Compute the offset based on teh shape strides and offsets @param shape the shape to compute @param offsets the offsets to compute @param strides the strides to compute @return the offset for the given shape,offset,and strides
ArrayUtil::calcOffset
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long calcOffsetLong(List<Integer> shape, List<Integer> offsets, List<Integer> strides) { if (shape.size() != offsets.size() || shape.size() != strides.size()) throw new IllegalArgumentException("Shapes,strides, and offsets must be the same size"); long ret = 0; for (int i = 0; i < offsets.size(); i++) { //we should only do this in the general case, not on vectors //the reason for this is we force everything including scalars //to be 2d if (shape.get(i) == 1 && offsets.size() > 2 && i > 0) continue; ret += (long) offsets.get(i) * strides.get(i); } return ret; }
Compute the offset based on teh shape strides and offsets @param shape the shape to compute @param offsets the offsets to compute @param strides the strides to compute @return the offset for the given shape,offset,and strides
ArrayUtil::calcOffsetLong
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long calcOffsetLong(int[] shape, int[] offsets, int[] strides) { if (shape.length != offsets.length || shape.length != strides.length) throw new IllegalArgumentException("Shapes,strides, and offsets must be the same size"); long ret = 0; for (int i = 0; i < offsets.length; i++) { if (shape[i] == 1) continue; ret += (long) offsets[i] * strides[i]; } return ret; }
Compute the offset based on teh shape strides and offsets @param shape the shape to compute @param offsets the offsets to compute @param strides the strides to compute @return the offset for the given shape,offset,and strides
ArrayUtil::calcOffsetLong
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int dotProduct(List<Integer> xs, List<Integer> ys) { int result = 0; int n = xs.size(); if (ys.size() != n) throw new IllegalArgumentException("Different array sizes"); for (int i = 0; i < n; i++) { result += xs.get(i) * ys.get(i); } return result; }
@param xs @param ys @return
ArrayUtil::dotProduct
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int dotProduct(int[] xs, int[] ys) { int result = 0; int n = xs.length; if (ys.length != n) throw new IllegalArgumentException("Different array sizes"); for (int i = 0; i < n; i++) { result += xs[i] * ys[i]; } return result; }
@param xs @param ys @return
ArrayUtil::dotProduct
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long dotProductLong(List<Integer> xs, List<Integer> ys) { long result = 0; int n = xs.size(); if (ys.size() != n) throw new IllegalArgumentException("Different array sizes"); for (int i = 0; i < n; i++) { result += (long) xs.get(i) * ys.get(i); } return result; }
@param xs @param ys @return
ArrayUtil::dotProductLong
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long dotProductLong2(List<Long> xs, List<Long> ys) { long result = 0; int n = xs.size(); if (ys.size() != n) throw new IllegalArgumentException("Different array sizes"); for (int i = 0; i < n; i++) { result += (long) xs.get(i) * ys.get(i); } return result; }
@param xs @param ys @return
ArrayUtil::dotProductLong2
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long dotProductLong(int[] xs, int[] ys) { long result = 0; int n = xs.length; if (ys.length != n) throw new IllegalArgumentException("Different array sizes"); for (int i = 0; i < n; i++) { result += (long) xs[i] * ys[i]; } return result; }
@param xs @param ys @return
ArrayUtil::dotProductLong
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] range(double[] data, int to) { return range(data, to, 1); }
Returns a subset of an array from 0 to "to" (exclusive) @param data the data to getFromOrigin a subset of @param to the end point of the data @return the subset of the data specified
ArrayUtil::range
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] range(double[] data, int to, int stride) { return range(data, to, stride, 1); }
Returns a subset of an array from 0 to "to" (exclusive) using the specified stride @param data the data to getFromOrigin a subset of @param to the end point of the data @param stride the stride to go through the array @return the subset of the data specified
ArrayUtil::range
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] range(double[] data, int to, int stride, int numElementsEachStride) { double[] ret = new double[to / stride]; if (ret.length < 1) ret = new double[1]; int count = 0; for (int i = 0; i < data.length; i += stride) { for (int j = 0; j < numElementsEachStride; j++) { if (i + j >= data.length || count >= ret.length) break; ret[count++] = data[i + j]; } } return ret; }
Returns a subset of an array from 0 to "to" using the specified stride @param data the data to getFromOrigin a subset of @param to the end point of the data @param stride the stride to go through the array @param numElementsEachStride the number of elements to collect at each stride @return the subset of the data specified
ArrayUtil::range
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] range(int from, int to, int increment) { int diff = Math.abs(from - to); int[] ret = new int[diff / increment]; if (ret.length < 1) ret = new int[1]; if (from < to) { int count = 0; for (int i = from; i < to; i += increment) { if (count >= ret.length) break; ret[count++] = i; } } else if (from > to) { int count = 0; for (int i = from - 1; i >= to; i -= increment) { if (count >= ret.length) break; ret[count++] = i; } } return ret; }
Generate an int array ranging from "from" to "to". The total number of elements is (from-to)/increment - i.e., range(0,2,1) returns [0,1] If from is > to this method will count backwards @param from the from @param to the end point of the data @param increment the amount to increment by @return the int array with a length equal to absoluteValue(from - to)
ArrayUtil::range
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] range(int from, int to) { if (from == to) return new int[0]; return range(from, to, 1); }
Generate an int array ranging from "from" to "to". The total number of elements is (from-to) - i.e., range(0,2) returns [0,1] If from is > to this method will count backwards @param from the from @param to the end point of the data @return the int array with a length equal to absoluteValue(from - to)
ArrayUtil::range
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] replace(int[] data, int index, int newValue) { int[] copy = copy(data); copy[index] = newValue; return copy; }
Return a copy of this array with the given index omitted @param data the data to copy @param index the index of the item to remove @param newValue the newValue to replace @return the new array with the omitted item
ArrayUtil::replace
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] keep(int[] data, int... index) { if (index.length == data.length) return data; int[] ret = new int[index.length]; int count = 0; for (int i = 0; i < data.length; i++) if (Ints.contains(index, i)) ret[count++] = data[i]; return ret; }
Return a copy of this array with only the given index(es) remaining @param data the data to copy @param index the index of the item to remove @return the new array with the omitted item
ArrayUtil::keep
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] keep(long[] data, long... index) { if (index.length == data.length) return data; long[] ret = new long[index.length]; int count = 0; for (int i = 0; i < data.length; i++) if (Longs.contains(index, i)) ret[count++] = data[i]; return ret; }
Return a copy of this array with only the given index(es) remaining @param data the data to copy @param index the index of the item to remove @return the new array with the omitted item
ArrayUtil::keep
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] keep(long[] data, int... index) { if (index.length == data.length) return data; long[] ret = new long[index.length]; int count = 0; for (int i = 0; i < data.length; i++) if (Ints.contains(index, i)) ret[count++] = data[i]; return ret; }
Return a copy of this array with only the given index(es) remaining @param data the data to copy @param index the index of the item to remove @return the new array with the omitted item
ArrayUtil::keep
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] removeIndex(long[] data, long... index) { if(data.length < 1) return data; if (index.length >= data.length) { throw new IllegalStateException("Illegal remove: indexes.length > data.length (index.length=" + index.length + ", data.length=" + data.length + ")"); } int offset = 0; long[] ret = new long[data.length - index.length + offset]; int count = 0; for (int i = 0; i < data.length; i++) if (!Longs.contains(index, i)) { ret[count++] = data[i]; } return ret; }
Return a copy of this array with the given index omitted PLEASE NOTE: index to be omitted must exist in source array. @param data the data to copy @param index the index of the item to remove @return the new array with the omitted item
ArrayUtil::removeIndex
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] removeIndex(int[] data, int... index) { if (index.length >= data.length) { throw new IllegalStateException("Illegal remove: indexes.length > data.length (index.length=" + index.length + ", data.length=" + data.length + ")"); } int offset = 0; int[] ret = new int[data.length - index.length + offset]; int count = 0; for (int i = 0; i < data.length; i++) if (!Ints.contains(index, i)) { ret[count++] = data[i]; } return ret; }
Return a copy of this array with the given index omitted PLEASE NOTE: index to be omitted must exist in source array. @param data the data to copy @param index the index of the item to remove @return the new array with the omitted item
ArrayUtil::removeIndex
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[][] zip(int[] as, int[] bs) { int[][] result = new int[as.length][2]; for (int i = 0; i < result.length; i++) { result[i] = new int[] {as[i], bs[i]}; } return result; }
Zip 2 arrays in to: @param as @param bs @return
ArrayUtil::zip
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] getTensorMmulShape(long[] aShape, long[] bShape, int[][] axes) { int validationLength = Math.min(axes[0].length, axes[1].length); for (int i = 0; i < validationLength; i++) { if (aShape[axes[0][i]] != bShape[axes[1][i]]) throw new IllegalArgumentException( "Size of the given axes a" + " t each dimension must be the same size."); if (axes[0][i] < 0) axes[0][i] += aShape.length; if (axes[1][i] < 0) axes[1][i] += bShape.length; } List<Integer> listA = new ArrayList<>(); for (int i = 0; i < aShape.length; i++) { if (!Ints.contains(axes[0], i)) listA.add(i); } List<Integer> listB = new ArrayList<>(); for (int i = 0; i < bShape.length; i++) { if (!Ints.contains(axes[1], i)) listB.add(i); } int n2 = 1; int aLength = Math.min(aShape.length, axes[0].length); for (int i = 0; i < aLength; i++) { n2 *= aShape[axes[0][i]]; } //if listA and listB are empty these do not initialize. //so initializing with {1} which will then get overridden if not empty long[] oldShapeA; if (listA.size() == 0) { oldShapeA = new long[] {1}; } else { oldShapeA = Longs.toArray(listA); for (int i = 0; i < oldShapeA.length; i++) oldShapeA[i] = aShape[(int) oldShapeA[i]]; } int n3 = 1; int bNax = Math.min(bShape.length, axes[1].length); for (int i = 0; i < bNax; i++) { n3 *= bShape[axes[1][i]]; } long[] oldShapeB; if (listB.isEmpty()) { oldShapeB = new long[] {1}; } else { oldShapeB = Longs.toArray(listB); for (int i = 0; i < oldShapeB.length; i++) oldShapeB[i] = bShape[(int) oldShapeB[i]]; } long[] aPlusB = Longs.concat(oldShapeA, oldShapeB); return aPlusB; }
Get the tensor matrix multiply shape @param aShape the shape of the first array @param bShape the shape of the second array @param axes the axes to do the multiply @return the shape for tensor matrix multiply
ArrayUtil::getTensorMmulShape
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] permute(int[] shape, int[] dimensions) { int[] ret = new int[shape.length]; for (int i = 0; i < shape.length; i++) { ret[i] = shape[dimensions[i]]; } return ret; }
Permute the given input switching the dimensions of the input shape array with in the order of the specified dimensions @param shape the shape to permute @param dimensions the dimensions @return
ArrayUtil::permute
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] argsort(int[] a) { return argsort(a, true); }
Original credit: https://github.com/alberts/array4j/blob/master/src/main/java/net/lunglet/util/ArrayUtils.java @param a @return
ArrayUtil::argsort
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] argsort(final int[] a, final boolean ascending) { Integer[] indexes = new Integer[a.length]; for (int i = 0; i < indexes.length; i++) { indexes[i] = i; } Arrays.sort(indexes, new Comparator<Integer>() { @Override public int compare(final Integer i1, final Integer i2) { return (ascending ? 1 : -1) * Ints.compare(a[i1], a[i2]); } }); int[] ret = new int[indexes.length]; for (int i = 0; i < ret.length; i++) ret[i] = indexes[i]; return ret; }
@param a @param ascending @return
ArrayUtil::argsort
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] convertNegativeIndices(int range, int[] axes) { int[] axesRet = ArrayUtil.range(0, range); int[] newAxes = ArrayUtil.copy(axes); for (int i = 0; i < axes.length; i++) { newAxes[i] = axes[axesRet[i]]; } return newAxes; }
Convert all dimensions in the specified axes array to be positive based on the specified range of values @param range @param axes @return
ArrayUtil::convertNegativeIndices
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] copyOfRangeFrom(int length, int from, int to) { return Arrays.copyOfRange(ArrayUtil.range(0, length), from, to); }
Generate an array from 0 to length and generate take a subset @param length the length to generate to @param from the begin of the interval to take @param to the end of the interval to take @return the generated array
ArrayUtil::copyOfRangeFrom
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static byte[] toByteArray(double[] doubleArray) { int times = Double.SIZE / Byte.SIZE; byte[] bytes = new byte[doubleArray.length * times]; for (int i = 0; i < doubleArray.length; i++) { ByteBuffer.wrap(bytes, i * times, times).putDouble(doubleArray[i]); } return bytes; }
@param doubleArray @return
ArrayUtil::toByteArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static byte[] toByteArraySimple(long[] longArray) { byte[] bytes = new byte[longArray.length]; for (int i = 0; i < longArray.length; i++) { bytes[i] = (byte) longArray[i]; } return bytes; }
Note this byte array conversion is a simple cast and not a true cast. Use {@link #toByteArraySimple(long[])} for a true cast. @param longArray @return
ArrayUtil::toByteArraySimple
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static byte[] toByteArray(long[] longArray) { int times = Long.SIZE / Byte.SIZE; byte[] bytes = new byte[longArray.length * times]; for (int i = 0; i < longArray.length; i++) { ByteBuffer.wrap(bytes, i * times, times).putLong(longArray[i]); } return bytes; }
@param longArray @return
ArrayUtil::toByteArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] toDoubleArraySimple(byte[] byteArray) { double[] doubles = new double[byteArray.length]; for (int i = 0; i < doubles.length; i++) { doubles[i] = (double) byteArray[i]; } return doubles; }
@param byteArray @return
ArrayUtil::toDoubleArraySimple
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] toDoubleArray(byte[] byteArray) { int times = Double.SIZE / Byte.SIZE; double[] doubles = new double[byteArray.length / times]; for (int i = 0; i < doubles.length; i++) { doubles[i] = ByteBuffer.wrap(byteArray, i * times, times).getDouble(); } return doubles; }
@param byteArray @return
ArrayUtil::toDoubleArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static byte[] toByteArray(float[] doubleArray) { int times = Float.SIZE / Byte.SIZE; byte[] bytes = new byte[doubleArray.length * times]; for (int i = 0; i < doubleArray.length; i++) { ByteBuffer.wrap(bytes, i * times, times).putFloat(doubleArray[i]); } return bytes; }
@param doubleArray @return
ArrayUtil::toByteArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static float[] toFloatArray(byte[] byteArray) { int times = Float.SIZE / Byte.SIZE; float[] doubles = new float[byteArray.length / times]; for (int i = 0; i < doubles.length; i++) { doubles[i] = ByteBuffer.wrap(byteArray, i * times, times).getFloat(); } return doubles; }
@param byteArray @return
ArrayUtil::toFloatArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static float[] toFloatArraySimple(byte[] byteArray) { float[] doubles = new float[byteArray.length]; for (int i = 0; i < doubles.length; i++) { doubles[i] = byteArray[i]; } return doubles; }
@param byteArray @return
ArrayUtil::toFloatArraySimple
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static byte[] toByteArray(int[] intArray) { int times = Integer.SIZE / Byte.SIZE; byte[] bytes = new byte[intArray.length * times]; for (int i = 0; i < intArray.length; i++) { ByteBuffer.wrap(bytes, i * times, times).putInt(intArray[i]); } return bytes; }
@param intArray @return
ArrayUtil::toByteArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] toIntArraySimple(byte[] byteArray) { int[] ints = new int[byteArray.length]; for (int i = 0; i < ints.length; i++) { ints[i] = byteArray[i]; } return ints; }
@param byteArray @return
ArrayUtil::toIntArraySimple
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] toIntArray(byte[] byteArray) { int times = Integer.SIZE / Byte.SIZE; int[] ints = new int[byteArray.length / times]; for (int i = 0; i < ints.length; i++) { ints[i] = ByteBuffer.wrap(byteArray, i * times, times).getInt(); } return ints; }
@param byteArray @return
ArrayUtil::toIntArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] removeIndex(int[] data, int index) { if (data == null) return null; if (index >= data.length) throw new IllegalArgumentException("Unable to remove index " + index + " was >= data.length"); if (data.length < 1) return data; if (index < 0) return data; int len = data.length; int[] result = new int[len - 1]; System.arraycopy(data, 0, result, 0, index); System.arraycopy(data, index + 1, result, index, len - index - 1); return result; }
Return a copy of this array with the given index omitted @param data the data to copy @param index the index of the item to remove @return the new array with the omitted item
ArrayUtil::removeIndex
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] valueStartingAt(int valueStarting, int[] copy, int idxFrom, int idxAt, int length) { int[] ret = new int[length]; Arrays.fill(ret, valueStarting); for (int i = 0; i < length; i++) { if (i + idxFrom >= copy.length || i + idxAt >= ret.length) break; ret[i + idxAt] = copy[i + idxFrom]; } return ret; }
Create a copy of the given array starting at the given index with the given length. The intent here is for striding. For example in slicing, you want the major stride to be first. You achieve this by taking the last index of the matrix's stride and putting this as the first stride of the new ndarray for slicing. All of the elements except the copied elements are initialized as the given value @param valueStarting the starting value @param copy the array to copy @param idxFrom the index to start at in the from array @param idxAt the index to start at in the return array @param length the length of the array to create @return the given array
ArrayUtil::valueStartingAt
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static Integer[] removeIndex(Integer[] data, int index) { if (data == null) return null; if (data.length < 1) return data; int len = data.length; Integer[] result = new Integer[len - 1]; System.arraycopy(data, 0, result, 0, index); System.arraycopy(data, index + 1, result, index, len - index - 1); return result; }
Returns the array with the item in index removed, if the array is empty it will return the array itself @param data the data to remove data from @param index the index of the item to remove @return a copy of the array with the removed item, or the array itself if empty
ArrayUtil::removeIndex
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] calcStridesFortran(int[] shape, int startNum) { if (shape.length == 2 && (shape[0] == 1 || shape[1] == 1)) { int[] ret = new int[2]; Arrays.fill(ret, startNum); return ret; } int dimensions = shape.length; int[] stride = new int[dimensions]; int st = startNum; for (int j = 0; j < stride.length; j++) { stride[j] = st; st *= shape[j]; } return stride; }
Computes the standard packed array strides for a given shape. @param shape the shape of a matrix: @param startNum the start number for the strides @return the strides for a matrix of n dimensions
ArrayUtil::calcStridesFortran
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] calcStridesFortran(long[] shape, int startNum) { if (shape.length == 2 && (shape[0] == 1 || shape[1] == 1)) { long[] ret = new long[2]; Arrays.fill(ret, startNum); return ret; } int dimensions = shape.length; long[] stride = new long[dimensions]; int st = startNum; for (int j = 0; j < stride.length; j++) { stride[j] = st; st *= shape[j]; } return stride; }
Computes the standard packed array strides for a given shape. @param shape the shape of a matrix: @param startNum the start number for the strides @return the strides for a matrix of n dimensions
ArrayUtil::calcStridesFortran
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] calcStridesFortran(int[] shape) { return calcStridesFortran(shape, 1); }
Computes the standard packed array strides for a given shape. @param shape the shape of a matrix: @return the strides for a matrix of n dimensions
ArrayUtil::calcStridesFortran
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] calcStrides(int[] shape, int startValue) { if (shape.length == 2 && (shape[0] == 1 || shape[1] == 1)) { int[] ret = new int[2]; Arrays.fill(ret, startValue); return ret; } int dimensions = shape.length; int[] stride = new int[dimensions]; int st = startValue; for (int j = dimensions - 1; j >= 0; j--) { stride[j] = st; st *= shape[j]; } return stride; }
Computes the standard packed array strides for a given shape. @param shape the shape of a matrix: @param startValue the startValue for the strides @return the strides for a matrix of n dimensions
ArrayUtil::calcStrides
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] calcStrides(long[] shape, int startValue) { if(shape == null) return null; if (shape.length == 2 && (shape[0] == 1 || shape[1] == 1)) { long[] ret = new long[2]; Arrays.fill(ret, startValue); return ret; } int dimensions = shape.length; long[] stride = new long[dimensions]; int st = startValue; for (int j = dimensions - 1; j >= 0; j--) { stride[j] = st; st *= shape[j]; } return stride; }
Computes the standard packed array strides for a given shape. @param shape the shape of a matrix: @param startValue the startValue for the strides @return the strides for a matrix of n dimensions
ArrayUtil::calcStrides
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static boolean isInverse(int[] first, int[] second) { int backWardCount = second.length - 1; for (int i = 0; i < first.length; i++) { if (first[i] != second[backWardCount--]) return false; } return true; }
Returns true if the given two arrays are reverse copies of each other @param first @param second @return
ArrayUtil::isInverse
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int nonOneStride(int[] arr) { for (int i = 0; i < arr.length; i++) if (arr[i] != 1) return arr[i]; return 1; }
For use with row vectors to ensure consistent strides with varying offsets @param arr the array to get the stride for @return the stride
ArrayUtil::nonOneStride
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] calcStrides(int[] shape) { return calcStrides(shape, 1); }
Computes the standard packed array strides for a given shape. @param shape the shape of a matrix: @return the strides for a matrix of n dimensions
ArrayUtil::calcStrides
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] reverseCopy(int[] e) { if (e.length < 1) return e; int[] copy = new int[e.length]; for (int i = 0; i <= e.length / 2; i++) { int temp = e[i]; copy[i] = e[e.length - i - 1]; copy[e.length - i - 1] = temp; } return copy; }
Create a backwards copy of the given array @param e the array to createComplex a reverse clone of @return the reversed copy
ArrayUtil::reverseCopy
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static void multiplyBy(int[] arr, int mult) { for (int i = 0; i < arr.length; i++) arr[i] *= mult; }
Multiply the given array by the given scalar @param arr the array to multily @param mult the scalar to multiply by
ArrayUtil::multiplyBy
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static void reverse(int[] e) { for (int i = 0; i <= e.length / 2; i++) { int temp = e[i]; e[i] = e[e.length - i - 1]; e[e.length - i - 1] = temp; } }
Reverse the passed in array in place @param e the array to reverse
ArrayUtil::reverse
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] flatten(double[][] arr) { if(arr.length == 0 || arr[0].length == 0 ) return new double[0]; double[] ret = new double[arr.length * arr[0].length]; int count = 0; for (int i = 0; i < arr.length; i++) { System.arraycopy(arr[i], 0, ret, count, arr[i].length); count += arr[i].length; } return ret; }
Convert a 2darray in to a flat array (row wise) @param arr the array to flatten @return a flattened representation of the array
ArrayUtil::flatten
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] flattenF(double[][] arr) { double[] ret = new double[arr.length * arr[0].length]; int count = 0; for (int j = 0; j < arr[0].length; j++) for (int i = 0; i < arr.length; i++) ret[count++] = arr[i][j]; return ret; }
Convert a 2darray in to a flat array (row wise) @param arr the array to flatten @return a flattened representation of the array
ArrayUtil::flattenF
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[][] toDouble(int[][] arr) { double[][] ret = new double[arr.length][arr[0].length]; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) ret[i][j] = arr[i][j]; } return ret; }
Cast an int array to a double array @param arr the array to cast @return the elements of this array cast as an int
ArrayUtil::toDouble
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static float[] combineFloat(List<float[]> nums) { int length = 0; for (int i = 0; i < nums.size(); i++) length += nums.get(i).length; float[] ret = new float[length]; int count = 0; for (float[] i : nums) { for (int j = 0; j < i.length; j++) { ret[count++] = i[j]; } } return ret; }
Combines a applyTransformToDestination of int arrays in to one flat int array @param nums the int arrays to combineDouble @return one combined int array
ArrayUtil::combineFloat
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static float[] combine(List<float[]> nums) { int length = 0; for (int i = 0; i < nums.size(); i++) length += nums.get(i).length; float[] ret = new float[length]; int count = 0; for (float[] i : nums) { for (int j = 0; j < i.length; j++) { ret[count++] = i[j]; } } return ret; }
Combines a apply of int arrays in to one flat int array @param nums the int arrays to combineDouble @return one combined int array
ArrayUtil::combine
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] combineDouble(List<double[]> nums) { int length = 0; for (int i = 0; i < nums.size(); i++) length += nums.get(i).length; double[] ret = new double[length]; int count = 0; for (double[] i : nums) { for (int j = 0; j < i.length; j++) { ret[count++] = i[j]; } } return ret; }
Combines a apply of int arrays in to one flat int array @param nums the int arrays to combineDouble @return one combined int array
ArrayUtil::combineDouble
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] combine(float[]... ints) { int length = 0; for (int i = 0; i < ints.length; i++) length += ints[i].length; double[] ret = new double[length]; int count = 0; for (float[] i : ints) { for (int j = 0; j < i.length; j++) { ret[count++] = i[j]; } } return ret; }
Combines a apply of int arrays in to one flat int array @param ints the int arrays to combineDouble @return one combined int array
ArrayUtil::combine
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] combine(int[]... ints) { int length = 0; for (int i = 0; i < ints.length; i++) length += ints[i].length; int[] ret = new int[length]; int count = 0; for (int[] i : ints) { for (int j = 0; j < i.length; j++) { ret[count++] = i[j]; } } return ret; }
Combines a apply of int arrays in to one flat int array @param ints the int arrays to combineDouble @return one combined int array
ArrayUtil::combine
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] combine(long[]... ints) { int length = 0; for (int i = 0; i < ints.length; i++) length += ints[i].length; long[] ret = new long[length]; int count = 0; for (long[] i : ints) { for (int j = 0; j < i.length; j++) { ret[count++] = i[j]; } } return ret; }
Combines a apply of long arrays in to one flat long array @param ints the int arrays to combineDouble @return one combined int array
ArrayUtil::combine
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static double[] flattenDoubleArray(Object doubleArray) { if (doubleArray instanceof double[]) return (double[]) doubleArray; LinkedList<Object> stack = new LinkedList<>(); stack.push(doubleArray); int[] shape = arrayShape(doubleArray); int length = ArrayUtil.prod(shape); double[] flat = new double[length]; int count = 0; while (!stack.isEmpty()) { Object current = stack.pop(); if (current instanceof double[]) { double[] arr = (double[]) current; for (int i = 0; i < arr.length; i++) flat[count++] = arr[i]; } else if (current instanceof Object[]) { Object[] o = (Object[]) current; for (int i = o.length - 1; i >= 0; i--) stack.push(o[i]); } else throw new IllegalArgumentException("Base array is not double[]"); } if (count != flat.length) throw new IllegalArgumentException("Fewer elements than expected. Array is ragged?"); return flat; }
Convert an arbitrary-dimensional rectangular double array to flat vector.<br> Can pass double[], double[][], double[][][], etc.
ArrayUtil::flattenDoubleArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static float[] flattenFloatArray(Object floatArray) { if (floatArray instanceof float[]) return (float[]) floatArray; LinkedList<Object> stack = new LinkedList<>(); stack.push(floatArray); int[] shape = arrayShape(floatArray); int length = ArrayUtil.prod(shape); float[] flat = new float[length]; int count = 0; while (!stack.isEmpty()) { Object current = stack.pop(); if (current instanceof float[]) { float[] arr = (float[]) current; for (int i = 0; i < arr.length; i++) flat[count++] = arr[i]; } else if (current instanceof Object[]) { Object[] o = (Object[]) current; for (int i = o.length - 1; i >= 0; i--) stack.push(o[i]); } else throw new IllegalArgumentException("Base array is not float[]"); } if (count != flat.length) throw new IllegalArgumentException("Fewer elements than expected. Array is ragged?"); return flat; }
Convert an arbitrary-dimensional rectangular float array to flat vector.<br> Can pass float[], float[][], float[][][], etc.
ArrayUtil::flattenFloatArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] arrayShape(Object array) { return arrayShape(array, false); }
Calculate the shape of an arbitrary multi-dimensional array. Assumes:<br> (a) array is rectangular (not ragged) and first elements (i.e., array[0][0][0]...) are non-null <br> (b) First elements have > 0 length. So array[0].length > 0, array[0][0].length > 0, etc.<br> Can pass any Java array opType: double[], Object[][][], float[][], etc.<br> Length of returned array is number of dimensions; returned[i] is size of ith dimension.
ArrayUtil::arrayShape
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] arrayShape(Object array, boolean allowSize0Dims) { int nDimensions = 0; Class<?> c = array.getClass().getComponentType(); while (c != null) { nDimensions++; c = c.getComponentType(); } int[] shape = new int[nDimensions]; Object current = array; for (int i = 0; i < shape.length - 1; i++) { shape[i] = ((Object[]) current).length; if(shape[i] == 0){ if(allowSize0Dims){ return shape; } throw new IllegalStateException("Cannot calculate array shape: Array has size 0 for dimension " + i ); } current = ((Object[]) current)[0]; } if (current instanceof Object[]) { shape[shape.length - 1] = ((Object[]) current).length; } else if (current instanceof double[]) { shape[shape.length - 1] = ((double[]) current).length; } else if (current instanceof float[]) { shape[shape.length - 1] = ((float[]) current).length; } else if (current instanceof long[]) { shape[shape.length - 1] = ((long[]) current).length; } else if (current instanceof int[]) { shape[shape.length - 1] = ((int[]) current).length; } else if (current instanceof byte[]) { shape[shape.length - 1] = ((byte[]) current).length; } else if (current instanceof char[]) { shape[shape.length - 1] = ((char[]) current).length; } else if (current instanceof boolean[]) { shape[shape.length - 1] = ((boolean[]) current).length; } else if (current instanceof short[]) { shape[shape.length - 1] = ((short[]) current).length; } else throw new IllegalStateException("Unknown array type"); //Should never happen return shape; }
Calculate the shape of an arbitrary multi-dimensional array.<br> Note that the method assumes the array is rectangular (not ragged) and first elements (i.e., array[0][0][0]...) are non-null <br> Note also that if allowSize0Dims is true, any elements are length 0, all subsequent dimensions will be reported as 0. i.e., a double[3][0][2] would be reported as shape [3,0,0]. If allowSize0Dims is false, an exception will be thrown for this case instead. Can pass any Java array opType: double[], Object[][][], float[][], etc.<br> Length of returned array is number of dimensions; returned[i] is size of ith dimension.
ArrayUtil::arrayShape
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int max(int[] in) { int max = Integer.MIN_VALUE; for (int i = 0; i < in.length; i++) if (in[i] > max) max = in[i]; return max; }
Calculate the shape of an arbitrary multi-dimensional array.<br> Note that the method assumes the array is rectangular (not ragged) and first elements (i.e., array[0][0][0]...) are non-null <br> Note also that if allowSize0Dims is true, any elements are length 0, all subsequent dimensions will be reported as 0. i.e., a double[3][0][2] would be reported as shape [3,0,0]. If allowSize0Dims is false, an exception will be thrown for this case instead. Can pass any Java array opType: double[], Object[][][], float[][], etc.<br> Length of returned array is number of dimensions; returned[i] is size of ith dimension. public static int[] arrayShape(Object array, boolean allowSize0Dims) { int nDimensions = 0; Class<?> c = array.getClass().getComponentType(); while (c != null) { nDimensions++; c = c.getComponentType(); } int[] shape = new int[nDimensions]; Object current = array; for (int i = 0; i < shape.length - 1; i++) { shape[i] = ((Object[]) current).length; if(shape[i] == 0){ if(allowSize0Dims){ return shape; } throw new IllegalStateException("Cannot calculate array shape: Array has size 0 for dimension " + i ); } current = ((Object[]) current)[0]; } if (current instanceof Object[]) { shape[shape.length - 1] = ((Object[]) current).length; } else if (current instanceof double[]) { shape[shape.length - 1] = ((double[]) current).length; } else if (current instanceof float[]) { shape[shape.length - 1] = ((float[]) current).length; } else if (current instanceof long[]) { shape[shape.length - 1] = ((long[]) current).length; } else if (current instanceof int[]) { shape[shape.length - 1] = ((int[]) current).length; } else if (current instanceof byte[]) { shape[shape.length - 1] = ((byte[]) current).length; } else if (current instanceof char[]) { shape[shape.length - 1] = ((char[]) current).length; } else if (current instanceof boolean[]) { shape[shape.length - 1] = ((boolean[]) current).length; } else if (current instanceof short[]) { shape[shape.length - 1] = ((short[]) current).length; } else throw new IllegalStateException("Unknown array type"); //Should never happen return shape; } /** Returns the maximum value in the array
ArrayUtil::max
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int min(int[] in) { int min = Integer.MAX_VALUE; for (int i = 0; i < in.length; i++) if (in[i] < min) min = in[i]; return min; }
Calculate the shape of an arbitrary multi-dimensional array.<br> Note that the method assumes the array is rectangular (not ragged) and first elements (i.e., array[0][0][0]...) are non-null <br> Note also that if allowSize0Dims is true, any elements are length 0, all subsequent dimensions will be reported as 0. i.e., a double[3][0][2] would be reported as shape [3,0,0]. If allowSize0Dims is false, an exception will be thrown for this case instead. Can pass any Java array opType: double[], Object[][][], float[][], etc.<br> Length of returned array is number of dimensions; returned[i] is size of ith dimension. public static int[] arrayShape(Object array, boolean allowSize0Dims) { int nDimensions = 0; Class<?> c = array.getClass().getComponentType(); while (c != null) { nDimensions++; c = c.getComponentType(); } int[] shape = new int[nDimensions]; Object current = array; for (int i = 0; i < shape.length - 1; i++) { shape[i] = ((Object[]) current).length; if(shape[i] == 0){ if(allowSize0Dims){ return shape; } throw new IllegalStateException("Cannot calculate array shape: Array has size 0 for dimension " + i ); } current = ((Object[]) current)[0]; } if (current instanceof Object[]) { shape[shape.length - 1] = ((Object[]) current).length; } else if (current instanceof double[]) { shape[shape.length - 1] = ((double[]) current).length; } else if (current instanceof float[]) { shape[shape.length - 1] = ((float[]) current).length; } else if (current instanceof long[]) { shape[shape.length - 1] = ((long[]) current).length; } else if (current instanceof int[]) { shape[shape.length - 1] = ((int[]) current).length; } else if (current instanceof byte[]) { shape[shape.length - 1] = ((byte[]) current).length; } else if (current instanceof char[]) { shape[shape.length - 1] = ((char[]) current).length; } else if (current instanceof boolean[]) { shape[shape.length - 1] = ((boolean[]) current).length; } else if (current instanceof short[]) { shape[shape.length - 1] = ((short[]) current).length; } else throw new IllegalStateException("Unknown array type"); //Should never happen return shape; } /** Returns the maximum value in the array public static int max(int[] in) { int max = Integer.MIN_VALUE; for (int i = 0; i < in.length; i++) if (in[i] > max) max = in[i]; return max; } /** Returns the minimum value in the array
ArrayUtil::min
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int argMax(int[] in) { int maxIdx = 0; for (int i = 1; i < in.length; i++) if (in[i] > in[maxIdx]) maxIdx = i; return maxIdx; }
Returns the index of the maximum value in the array. * If two entries have same maximum value, index of the first one is returned.
ArrayUtil::argMax
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int argMin(int[] in) { int minIdx = 0; for (int i = 1; i < in.length; i++) if (in[i] < in[minIdx]) minIdx = i; return minIdx; }
Returns the index of the minimum value in the array. * If two entries have same minimum value, index of the first one is returned.
ArrayUtil::argMin
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int argMax(long[] in) { int maxIdx = 0; for (int i = 1; i < in.length; i++) if (in[i] > in[maxIdx]) maxIdx = i; return maxIdx; }
Returns the index of the maximum value in the array. * If two entries have same maximum value, index of the first one is returned.
ArrayUtil::argMax
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int argMin(long[] in) { int minIdx = 0; for (int i = 1; i < in.length; i++) if (in[i] < in[minIdx]) minIdx = i; return minIdx; }
Returns the index of the minimum value in the array. * If two entries have same minimum value, index of the first one is returned.
ArrayUtil::argMin
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] buildHalfVector(Random rng, int length) { int[] result = new int[length]; List<Integer> indexes = new ArrayList<>(); // we add indexes from second half only for (int i = result.length - 1; i >= result.length / 2; i--) { indexes.add(i); } Collections.shuffle(indexes, rng); for (int i = 0; i < result.length; i++) { if (i < result.length / 2) { result[i] = indexes.get(0); indexes.remove(0); } else result[i] = -1; } return result; }
@return
ArrayUtil::buildHalfVector
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int fromBoolean(boolean bool) { return bool ? 1 : 0; }
Convert an int @param bool @return
ArrayUtil::fromBoolean
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static <T> void assertNotRagged(T[] array){ Class<?> c = array.getClass().getComponentType(); int[] arrayShape = ArrayUtil.arrayShape(array, true); int rank = arrayShape.length; if(rank == 1){ //Rank 1 cannot be ragged return; } if(rank >= 2){ for( int i = 1; i < arrayShape[0]; i++) { Object subArray = array[i]; int len = arrayLength(subArray); Preconditions.checkState(arrayShape[1] == len, "Ragged array detected: array[0].length=%s does not match array[%s].length=%s", arrayShape[1], i, len); } if(rank == 2) return; } if(rank >= 3){ for( int i = 0; i < arrayShape[0]; i++) { for( int j = 0; j < arrayShape[1]; j++) { Object subArray = ((Object[][])array)[i][j]; int len = arrayLength(subArray); Preconditions.checkState(arrayShape[2] == len, "Ragged array detected: array[0][0].length=%s does not match array[%s][%s].length=%s", arrayShape[2], i, j, len); } } if(rank == 3) return; } if(rank >= 4){ for( int i = 0; i < arrayShape[0]; i++) { for( int j = 0; j<arrayShape[1]; j++) { for( int k = 0; k < arrayShape[2]; k++) { Object subArray = ((Object[][][])array)[i][j][k]; int len = arrayLength(subArray); Preconditions.checkState(arrayShape[3] == len, "Ragged array detected: array[0][0][0].length=%s does not match array[%s][%s][%s].length=%s", arrayShape[3], i, j, k, len); } } } } }
Assert that the specified array is not ragged (i.e., is rectangular).<br> Can be used to check Object arrays with any number of dimensions (up to rank 4), or primitive arrays with rank 2 or higher<br> An IllegalStateException is thrown if the array is ragged @param array Array to check
ArrayUtil::assertNotRagged
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int arrayLength(Object current){ if (current instanceof Object[]) { return ((Object[]) current).length; } else if (current instanceof double[]) { return ((double[]) current).length; } else if (current instanceof float[]) { return ((float[]) current).length; } else if (current instanceof long[]) { return ((long[]) current).length; } else if (current instanceof int[]) { return ((int[]) current).length; } else if (current instanceof byte[]) { return ((byte[]) current).length; } else if (current instanceof char[]) { return ((char[]) current).length; } else if (current instanceof boolean[]) { return ((boolean[]) current).length; } else if (current instanceof short[]) { return ((short[]) current).length; } else throw new IllegalStateException("Unknown array type (or not an array): " + current.getClass()); //Should never happen }
Calculate the length of the object or primitive array. If @param current @return
ArrayUtil::arrayLength
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static int[] invertPermutation(int... input){ int[] target = new int[input.length]; for(int i = 0 ; i < input.length ; i++){ target[input[i]] = i; } return target; }
Compute the inverse permutation indices for a permutation operation<br> Example: if input is [2, 0, 1] then output is [1, 2, 0]<br> The idea is that x.permute(input).permute(invertPermutation(input)) == x @param input 1D indices for permutation @return 1D inverted permutation
ArrayUtil::invertPermutation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static long[] invertPermutation(long... input){ long[] target = new long[input.length]; for(int i = 0 ; i < input.length ; i++){ target[(int) input[i]] = i; } return target; }
@see #invertPermutation(int...) @param input 1D indices for permutation @return 1D inverted permutation
ArrayUtil::invertPermutation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static boolean isEmptyShape(long[] shape){ for( long l : shape){ if(l == 0) return true; } return false; }
Is this shape an empty shape? Shape is considered to be an empty shape if it contains any zeros. Note: a length 0 shape is NOT considered empty (it's rank 0 scalar) @param shape Shape to check @return True if shape contains zeros
ArrayUtil::isEmptyShape
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public static boolean isEmptyShape(int[] shape){ for( int i : shape){ if(i == 0) return true; } return false; }
Is this shape an empty shape? Shape is considered to be an empty shape if it contains any zeros. Note: a length 0 shape is NOT considered empty (it's rank 0 scalar) @param shape Shape to check @return True if shape contains zeros
ArrayUtil::isEmptyShape
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArrayUtil.java
Apache-2.0
public Factorial() { if (a.isEmpty()) { a.add(BigInteger.ONE); a.add(BigInteger.ONE); } }
ctor(). Initialize the vector of the factorials with 0!=1 and 1!=1.
Factorial::Factorial
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Factorial.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Factorial.java
Apache-2.0
public BigInteger at(int n) { while (a.size() <= n) { final int lastn = a.size() - 1; final BigInteger nextn = BigInteger.valueOf(lastn + 1); a.add(a.get(lastn).multiply(nextn)); } return a.get(n); }
Compute the factorial of the non-negative integer. @param n the argument to the factorial, non-negative. @return the factorial of n.
Factorial::at
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Factorial.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Factorial.java
Apache-2.0
public static boolean nameExistsInPath(String name) { String path = System.getenv(PATH_ENV_VARIABLE); String[] dirs = path.split(File.pathSeparator); for (String dir : dirs) { File dirFile = new File(dir); if (!dirFile.exists()) continue; if (dirFile.isFile() && dirFile.getName().equals(name)) return true; else { Iterator<File> files = FileUtils.iterateFiles(dirFile, null, false); while (files.hasNext()) { File curr = files.next(); if (curr.getName().equals(name)) return true; } } } return false; }
Check if a file exists in the path @param name the name of the file @return true if the name exists false otherwise
Paths::nameExistsInPath
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Paths.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Paths.java
Apache-2.0
protected void set(final int n, final Rational value) { final int nindx = n / 2; if (nindx < a.size()) { a.set(nindx, value); } else { while (a.size() < nindx) { a.add(Rational.ZERO); } a.add(value); } }
Set a coefficient in the internal table. @param n the zero-based index of the coefficient. n=0 for the constant term. @param value the new value of the coefficient.
Bernoulli::set
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Bernoulli.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Bernoulli.java
Apache-2.0
public Rational at(int n) { if (n == 1) { return (new Rational(-1, 2)); } else if (n % 2 != 0) { return Rational.ZERO; } else { final int nindx = n / 2; if (a.size() <= nindx) { for (int i = 2 * a.size(); i <= n; i += 2) { set(i, doubleSum(i)); } } return a.get(nindx); } }
The Bernoulli number at the index provided. @param n the index, non-negative. @return the B_0=1 for n=0, B_1=-1/2 for n=1, B_2=1/6 for n=2 etc
Bernoulli::at
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Bernoulli.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Bernoulli.java
Apache-2.0