code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
833 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public Rational multiply(final Rational val) { BigInteger num = a.multiply(val.a); BigInteger deno = b.multiply(val.b); /* Normalization to an coprime format will be done inside * the ctor() and is not duplicated here. */ return (new Rational(num, deno)); } /* Rational.multiply */
Multiply by another fraction. @param val a second rational number. @return the product of this with the val.
Rational::multiply
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational multiply(final BigInteger val) { Rational val2 = new Rational(val, BigInteger.ONE); return (multiply(val2)); } /* Rational.multiply */
Multiply by a BigInteger. @param val a second number. @return the product of this with the value.
Rational::multiply
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational multiply(final int val) { BigInteger tmp = BigInteger.valueOf(val); return multiply(tmp); } /* Rational.multiply */
Multiply by an integer. @param val a second number. @return the product of this with the value.
Rational::multiply
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational pow(int exponent) { if (exponent == 0) { return new Rational(1, 1); } BigInteger num = a.pow(Math.abs(exponent)); BigInteger deno = b.pow(Math.abs(exponent)); if (exponent > 0) { return (new Rational(num, deno)); } else { return (new Rational(deno, num)); } } /* Rational.pow */
Power to an integer. @param exponent the exponent. @return this value raised to the power given by the exponent. If the exponent is 0, the value 1 is returned.
Rational::pow
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational divide(final Rational val) { BigInteger num = a.multiply(val.b); BigInteger deno = b.multiply(val.a); /* Reduction to a coprime format is done inside the ctor, * and not repeated here. */ return (new Rational(num, deno)); } /* Rational.divide */
Divide by another fraction. @param val A second rational number. @return The value of this/val
Rational::divide
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational divide(BigInteger val) { Rational val2 = new Rational(val, BigInteger.ONE); return (divide(val2)); } /* Rational.divide */
Divide by an integer. @param val a second number. @return the value of this/val
Rational::divide
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational divide(int val) { Rational val2 = new Rational(val, 1); return (divide(val2)); } /* Rational.divide */
Divide by an integer. @param val A second number. @return The value of this/val
Rational::divide
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational add(Rational val) { BigInteger num = a.multiply(val.b).add(b.multiply(val.a)); BigInteger deno = b.multiply(val.b); return (new Rational(num, deno)); } /* Rational.add */
Add another fraction. @param val The number to be added @return this+val.
Rational::add
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational add(BigInteger val) { Rational val2 = new Rational(val, BigInteger.ONE); return (add(val2)); } /* Rational.add */
Add another integer. @param val The number to be added @return this+val.
Rational::add
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational negate() { return (new Rational(a.negate(), b)); } /* Rational.negate */
Compute the negative. @return -this.
Rational::negate
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational subtract(Rational val) { Rational val2 = val.negate(); return (add(val2)); } /* Rational.subtract */
Subtract another fraction. 7 @param val the number to be subtracted from this @return this - val.
Rational::subtract
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational subtract(BigInteger val) { Rational val2 = new Rational(val, BigInteger.ONE); return (subtract(val2)); } /* Rational.subtract */
Subtract an integer. @param val the number to be subtracted from this @return this - val.
Rational::subtract
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public BigInteger numer() { return a; }
Get the numerator. @return The numerator of the reduced fraction.
Rational::numer
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public BigInteger denom() { return b; }
Get the denominator. @return The denominator of the reduced fraction.
Rational::denom
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational abs() { return (new Rational(a.abs(), b.abs())); }
Absolute value. @return The absolute (non-negative) value of this.
Rational::abs
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public BigInteger floor() { /* is already integer: return the numerator */ if (b.compareTo(BigInteger.ONE) == 0) { return a; } else if (a.compareTo(BigInteger.ZERO) > 0) { return a.divide(b); } else { return a.divide(b).subtract(BigInteger.ONE); } } /* Rational.floor */
floor(): the nearest integer not greater than this. @return The integer rounded towards negative infinity.
Rational::floor
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public BigInteger trunc() { /* is already integer: return the numerator */ if (b.compareTo(BigInteger.ONE) == 0) { return a; } else { return a.divide(b); } } /* Rational.trunc */
Remove the fractional part. @return The integer rounded towards zero.
Rational::trunc
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public int compareTo(final Rational val) { /* Since we have always kept the denominators positive, * simple cross-multiplying works without changing the sign. */ final BigInteger left = a.multiply(val.b); final BigInteger right = val.a.multiply(b); return left.compareTo(right); } /* Rational.compareTo */
Compares the value of this with another constant. @param val the other constant to compare with @return -1, 0 or 1 if this number is numerically less than, equal to, or greater than val.
Rational::compareTo
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public double doubleValue() { /* To meet the risk of individual overflows of the exponents of * a separate invocation a.doubleValue() or b.doubleValue(), we divide first * in a BigDecimal environment and converst the result. */ BigDecimal adivb = (new BigDecimal(a)).divide(new BigDecimal(b), MathContext.DECIMAL128); return adivb.doubleValue(); } /* Rational.doubleValue */
Return a double value representation. @return The value with double precision.
Rational::doubleValue
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public float floatValue() { BigDecimal adivb = (new BigDecimal(a)).divide(new BigDecimal(b), MathContext.DECIMAL128); return adivb.floatValue(); } /* Rational.floatValue */
Return a float value representation. @return The value with single precision.
Rational::floatValue
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public BigDecimal BigDecimalValue(MathContext mc) { /* numerator and denominator individually rephrased */ BigDecimal n = new BigDecimal(a); BigDecimal d = new BigDecimal(b); return n.divide(d, mc); } /* Rational.BigDecimnalValue */
Return a representation as BigDecimal. @param mc the mathematical context which determines precision, rounding mode etc @return A representation as a BigDecimal floating point number.
Rational::BigDecimalValue
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public String toFString(int digits) { if (b.compareTo(BigInteger.ONE) != 0) { MathContext mc = new MathContext(digits, RoundingMode.DOWN); BigDecimal f = (new BigDecimal(a)).divide(new BigDecimal(b), mc); return (f.toString()); } else { return a.toString(); } } /* Rational.toFString */
Return a string in floating point format. @param digits The precision (number of digits) @return The human-readable version in base 10.
Rational::toFString
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational max(final Rational val) { if (compareTo(val) > 0) { return this; } else { return val; } } /* Rational.max */
Compares the value of this with another constant. @param val The other constant to compare with @return The arithmetic maximum of this and val.
Rational::max
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational min(final Rational val) { if (compareTo(val) < 0) { return this; } else { return val; } } /* Rational.min */
Compares the value of this with another constant. @param val The other constant to compare with @return The arithmetic minimum of this and val.
Rational::min
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational Pochhammer(final BigInteger n) { if (n.compareTo(BigInteger.ZERO) < 0) { return null; } else if (n.compareTo(BigInteger.ZERO) == 0) { return Rational.ONE; } else { /* initialize results with the current value */ Rational res = new Rational(a, b); BigInteger i = BigInteger.ONE; for (; i.compareTo(n) < 0; i = i.add(BigInteger.ONE)) { res = res.multiply(add(i)); } return res; } } /* Rational.pochhammer */
Compute Pochhammer's symbol (this)_n. @param n The number of product terms in the evaluation. @return Gamma(this+n)/Gamma(this) = this*(this+1)*...*(this+n-1).
Rational::Pochhammer
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public Rational Pochhammer(int n) { return Pochhammer(BigInteger.valueOf(n)); } /* Rational.pochhammer */
Compute pochhammer's symbol (this)_n. @param n The number of product terms in the evaluation. @return Gamma(this+n)/GAMMA(this).
Rational::Pochhammer
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
protected void normalize() { /* compute greatest common divisor of numerator and denominator */ final BigInteger g = a.gcd(b); if (g.compareTo(BigInteger.ONE) > 0) { a = a.divide(g); b = b.divide(g); } if (b.compareTo(BigInteger.ZERO) == -1) { a = a.negate(); b = b.negate(); } } /* Rational.normalize */
Normalize to coprime numerator and denominator. Also copy a negative sign of the denominator to the numerator.
Rational::normalize
java
deeplearning4j/deeplearning4j
nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/Rational.java
Apache-2.0
public static boolean[] toBooleanArray(byte[] input) { boolean[] output = new boolean[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] != 0; } return output; }
Converts a byte array to a boolean array. @param input the input byte array @return a boolean array with true values for nonzero bytes and false values for zero bytes
ArrayUtil::toBooleanArray
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[] toBooleanArray(short[] input) { boolean[] output = new boolean[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] != 0; } return output; }
Converts a short array to a boolean array. @param input the input short array @return a boolean array with true values for nonzero shorts and false values for zero shorts
ArrayUtil::toBooleanArray
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[] toBooleanArray(int[] input) { boolean[] output = new boolean[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] != 0; } return output; }
Converts an int array to a boolean array. @param input the input int array @return a boolean array with true values for nonzero integers and false values for zero integers
ArrayUtil::toBooleanArray
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[] toBooleanArray(long[] input) { boolean[] output = new boolean[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] != 0L; } return output; }
Converts a long array to a boolean array. @param input the input long array @return a boolean array with true values for nonzero longs and false values for zero longs
ArrayUtil::toBooleanArray
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[] toBooleanArray(float[] input) { boolean[] output = new boolean[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] != 0.0f; } return output; }
Converts a float array to a boolean array. @param input the input float array @return a boolean array with true values for nonzero floats and false values for zero floats
ArrayUtil::toBooleanArray
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[] toBooleanArray(double[] input) { boolean[] output = new boolean[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] != 0.0; } return output; }
Converts a double array to a boolean array. @param input the input double array @return a boolean array with true values for nonzero doubles and false values for zero doubles
ArrayUtil::toBooleanArray
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[] fromFloat(float[] elements) { boolean[] ret = new boolean[elements.length]; for(int i = 0; i < elements.length; i++) { ret[i] = elements[i] == 0.0f ? false : true; } return ret; }
Create a boolean array from a float array. @param elements the elements to create @return the returned float array
ArrayUtil::fromFloat
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[] nTimes(boolean element,int n) { boolean[] ret = new boolean[n]; //boolean values default to false. Only need to iterate when true. if(element) { for (int i = 0; i < n; i++) { ret[i] = element; } } return ret; }
Generate an array with n elements of the same specified value. @param element the element to create n copies of @param n the number of elements @return the created array
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 int[] toIntArray(short[] input) { int[] output = new int[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a short array to an int array. @param input the input short array @return an int array with each element equal to the corresponding short value
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[] toIntArray(boolean[] input) { int[] output = new int[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] ? 1 : 0; } return output; }
Converts a short array to an int array. @param input the input short array @return an int array with each element equal to the corresponding int value
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[] toIntArray(char[] input) { int[] output = new int[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a char array to an int array. @param input the input char array @return an int array with each element equal to the corresponding char value
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[] toIntArray(int[] input) { int[] output = new int[input.length]; System.arraycopy(input, 0, output, 0, input.length); return output; }
Converts an int array to an int array (i.e., returns a copy of the input array). @param input the input int array @return a new int array with the same values as the input array
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[] toIntArray(long[] input) { int[] output = new int[input.length]; for (int i = 0; i < input.length; i++) { output[i] = (int) input[i]; } return output; }
Converts a long array to an int array. @param input the input long array @return an int array with each element equal to the corresponding long value cast to an int
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[] toIntArray(float[] input) { int[] output = new int[input.length]; for (int i = 0; i < input.length; i++) { output[i] = (int) input[i]; } return output; }
Converts a float array to an int array. @param input the input float array @return an int array with each element equal to the corresponding float value cast to an int
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[] toIntArray(double[] input) { int[] output = new int[input.length]; for (int i = 0; i < input.length; i++) { output[i] = (int) input[i]; } return output; }
Converts a double array to an int array. @param input the input double array @return an int array with each element equal to the corresponding double value cast to an int
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 double[] toDoubleArray(short[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a short array to a double array. @param input the input short array @return a double array with each element equal to the corresponding short value
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 double[] toDoubleArray(char[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a char array to a double array. @param input the input char array @return a double array with each element equal to the corresponding char value
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 double[] toDoubleArray(boolean[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] ? 1.0 : 0.0; } return output; }
Converts a boolean array to a double array. @param input the input boolean array @return a double array with each element equal to the corresponding double value
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 double[] toDoubleArray(int[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts an int array to a double array. @param input the input int array @return a double array with each element equal to the corresponding int value
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 double[] toDoubleArray(long[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a long array to a double array. @param input the input long array @return a double array with each element equal to the corresponding long value
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 double[] toDoubleArray(float[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a float array to a double array. @param input the input float array @return a double array with each element equal to the corresponding float value
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 double[] toDoubleArray(double[] input) { double[] output = new double[input.length]; System.arraycopy(input, 0, output, 0, input.length); return output; }
Converts a double array to a double array (i.e., returns a copy of the input array). @param input the input double array @return a new double array with the same values as the input array
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 long[] toLongArray(byte[] input) { long[] output = new long[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a byte array to a long array. @param input the input byte array @return a long array with each element equal to the corresponding byte value
ArrayUtil::toLongArray
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[] toLongArray(boolean[] input) { long[] output = new long[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] ? 1 : 0; } return output; }
Converts a byte array to a long array. @param input the input boolean array @return a long array with each element equal to the corresponding long value
ArrayUtil::toLongArray
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[] toLongArray(short[] input) { long[] output = new long[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a short array to a long array. @param input the input short array @return a long array with each element equal to the corresponding short value
ArrayUtil::toLongArray
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[] toLongArray(char[] input) { long[] output = new long[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a char array to a long array. @param input the input char array @return a long array with each element equal to the corresponding char value
ArrayUtil::toLongArray
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[] toLongArrayInt(int[] input) { long[] output = new long[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts an int array to a long array. @param input the input int array @return a long array with each element equal to the corresponding int value
ArrayUtil::toLongArrayInt
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[] toLongArrayFloat(float[] input) { long[] output = new long[input.length]; for (int i = 0; i < input.length; i++) { output[i] = (long) input[i]; } return output; }
Converts a float array to a long array. @param input the input float array @return a long array with each element equal to the corresponding float value
ArrayUtil::toLongArrayFloat
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[] toLongArray(double[] input) { long[] output = new long[input.length]; for (int i = 0; i < input.length; i++) { output[i] = (long) input[i]; } return output; }
Converts a double array to a long array. @param input the input double array @return a long array with each element equal to the corresponding double value
ArrayUtil::toLongArray
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[] toLongArray(long[] input) { long[] output = new long[input.length]; System.arraycopy(input, 0, output, 0, input.length); return output; }
Converts a long array to a long array (i.e., returns a copy of the input array). @param input the input long array @return a new long array with the same values as the input array
ArrayUtil::toLongArray
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(short[] input) { float[] output = new float[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a short array to a float array. @param input the input short array @return a float array with each element equal to the corresponding short value
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[] toFloatArray(boolean[] input) { float[] output = new float[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i] ? 1.0f : 0.0f; } return output; }
Converts a boolean array to a float array. @param input the input boolean array @return a float array with each element equal to the corresponding boolean value
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[] toFloatArray(char[] input) { float[] output = new float[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a char array to a float array. @param input the input char array @return a float array with each element equal to the corresponding char value
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[] toFloatArray(int[] input) { float[] output = new float[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts an int array to a float array. @param input the input int array @return a float array with each element equal to the corresponding int value
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[] toFloatArray(long[] input) { float[] output = new float[input.length]; for (int i = 0; i < input.length; i++) { output[i] = input[i]; } return output; }
Converts a long array to a float array. @param input the input long array @return a float array with each element equal to the corresponding long value
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[] toFloatArray(double[] input) { float[] output = new float[input.length]; for (int i = 0; i < input.length; i++) { output[i] = (float) input[i]; } return output; }
Converts a double array to a float array. @param input the input double array @return a float array with each element equal to the corresponding double value
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[] toFloatArray(float[] input) { float[] output = new float[input.length]; System.arraycopy(input, 0, output, 0, input.length); return output; }
Converts a float array to a float array (i.e., returns a copy of the input array). @param input the input float array @return a new float array with the same values as the input array
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 <T> T[] concat(Class<T> clazz,T[]...arrs) { int totalLength = 0; for(T[] arr : arrs) totalLength += arr.length; T[] ret = (T[]) Array.newInstance(clazz,totalLength); int count = 0; for(T[] arr : arrs) { for(T input : arr) { ret[count] = input; count++; } } return ret; }
Concat all the elements @param arrs the input arrays @return @param <T>
ArrayUtil::concat
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 containsAnyNegative(int[] arr) { if(arr == null) return false; for(int i = 0; i < arr.length; i++) { if(arr[i] < 0) return true; } return false; }
Returns true if any array elements are negative. If the array is null, it returns false @param arr the array to test @return
ArrayUtil::containsAnyNegative
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 anyLargerThan(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::anyLargerThan
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 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 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 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 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[] 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[][] 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 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[] 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