public static void assertSameShape(INDArray n, INDArray n2) { if (!Shape.shapeEquals(n.shape(), n2.shape())) throw new IllegalStateException("Mis matched shapes: " + Arrays.toString(n.shape()) + ", " + Arrays.toString(n2.shape())); }
if (!Shape.shapeEquals(specifiedShape, entry.getValue().shape())) { throw new ND4JIllegalStateException("Place holder shape specified was " + Arrays.toString(specifiedShape) + " but array shape was " + Arrays.toString(entry.getValue().shape()));
/** * * @param real */ protected void copyFromReal(INDArray real) { if (!Shape.shapeEquals(shape(), real.shape())) throw new IllegalStateException("Unable to copy array. Not the same shape"); INDArray linear = real.linearView(); IComplexNDArray thisLinear = linearView(); for (int i = 0; i < linear.length(); i++) { thisLinear.putScalar(i, Nd4j.createComplexNumber(linear.getDouble(i), 0.0)); } }
protected void assertSlice(INDArray put, long slice) { assert slice <= slices() : "Invalid slice specified " + slice; long[] sliceShape = put.shape(); if (Shape.isRowVectorShape(sliceShape)) { return; } else { long[] requiredShape = ArrayUtil.removeIndex(shape(), 0); //no need to compare for scalar; primarily due to shapes either being [1] or length 0 if (put.isScalar()) return; if (isVector() && put.isVector() && put.length() < length()) return; //edge case for column vectors if (Shape.isColumnVectorShape(sliceShape)) return; if (!Shape.shapeEquals(sliceShape, requiredShape) && !Shape.isRowVectorShape(requiredShape) && !Shape.isRowVectorShape(sliceShape)) throw new IllegalStateException(String.format("Invalid shape size of %s . Should have been %s ", Arrays.toString(sliceShape), Arrays.toString(requiredShape))); } }
if (!Shape.shapeEquals(shape(), n.shape())) { return false;
if (Shape.shapeEquals(shape, shape())) return this;
if (!Shape.shapeEquals(shape(), n.shape())) return false;
/** * in place subtraction of two matrices * * @param other the second ndarray to subtract * @param result the result ndarray * @return the result of the subtraction */ @Override public INDArray subi(INDArray other, INDArray result) { if (other.isScalar()) { return subi(other.getDouble(0), result); } if (isScalar()) { return other.rsubi(getDouble(0), result); } if(!Shape.shapeEquals(this.shape(),other.shape())) { int[] broadcastDimensions = Shape.getBroadcastDimensions(this.shape(),other.shape()); Nd4j.getExecutioner().exec(new BroadcastSubOp(this,other,result,broadcastDimensions),broadcastDimensions); return result; } LinAlgExceptions.assertSameShape(other, result); Nd4j.getExecutioner().exec(new OldSubOp(this, other,result)); if (Nd4j.ENFORCE_NUMERICAL_STABILITY) Nd4j.clearNans(result); return result; }
/** * in place (element wise) multiplication of two matrices * * @param other the second ndarray to multiply * @param result the result ndarray * @return the result of the multiplication */ @Override public INDArray muli(INDArray other, INDArray result) { if (other.isScalar()) { return muli(other.getDouble(0), result); } if (isScalar()) { return other.muli(getDouble(0), result); } if(!Shape.shapeEquals(this.shape(),other.shape())) { int[] broadcastDimensions = Shape.getBroadcastDimensions(this.shape(),other.shape()); Nd4j.getExecutioner().exec(new BroadcastMulOp(this,other,result,broadcastDimensions),broadcastDimensions); return result; } LinAlgExceptions.assertSameShape(other, result); Nd4j.getExecutioner().exec(new OldMulOp(this, other, result, length())); if (Nd4j.ENFORCE_NUMERICAL_STABILITY) Nd4j.clearNans(result); return result; }
/** * in place (element wise) division of two matrices * * @param other the second ndarray to divide * @param result the result ndarray * @return the result of the divide */ @Override public INDArray divi(INDArray other, INDArray result) { if (other.isScalar()) { return divi(other.getDouble(0), result); } if (isScalar()) { return other.rdivi(getDouble(0), result); } if(!Shape.shapeEquals(this.shape(),other.shape())) { int[] broadcastDimensions = Shape.getBroadcastDimensions(this.shape(),other.shape()); Nd4j.getExecutioner().exec(new BroadcastDivOp(this,other,result,broadcastDimensions),broadcastDimensions); return result; } LinAlgExceptions.assertSameShape(other, result); Nd4j.getExecutioner().exec(new OldDivOp(this, other, result, length())); if (Nd4j.ENFORCE_NUMERICAL_STABILITY) Nd4j.clearNans(result); return result; }
/** * in place addition of two matrices * * @param other the second ndarray to add * @param result the result ndarray * @return the result of the addition */ @Override public INDArray addi(INDArray other, INDArray result) { if (other.isScalar()) { return result.addi(other.getDouble(0), result); } if (isScalar()) { return other.addi(getDouble(0), result); } if(!Shape.shapeEquals(this.shape(),other.shape())) { int[] broadcastDimensions = Shape.getBroadcastDimensions(this.shape(),other.shape()); result = Nd4j.createUninitialized(Shape.broadcastOutputShape(this.shape(),other.shape())); Nd4j.getExecutioner().exec(new BroadcastAddOp(this,other,result,broadcastDimensions),broadcastDimensions); return result; } LinAlgExceptions.assertSameShape(other, result); Nd4j.getExecutioner().exec(new OldAddOp(this, other, result, length())); if (Nd4j.ENFORCE_NUMERICAL_STABILITY) Nd4j.clearNans(result); return result; }
else { assert Shape.shapeEquals(view.shape(), put.shape()); IComplexNDArray linear = view.linearView(); IComplexNDArray putLinearView = put.linearView();
view.putScalar(i, put.getDouble(i)); else { assert Shape.shapeEquals(view.shape(), put.shape()); INDArray linear = view; INDArray putLinearView = put;
/** * * @param real */ protected void copyFromReal(INDArray real) { if (!Shape.shapeEquals(shape(), real.shape())) throw new IllegalStateException("Unable to copy array. Not the same shape"); INDArray linear = real.linearView(); IComplexNDArray thisLinear = linearView(); for (int i = 0; i < linear.length(); i++) { thisLinear.putScalar(i, Nd4j.createComplexNumber(linear.getDouble(i), 0.0)); } }
protected void assertSlice(INDArray put, int slice) { assert slice <= slices() : "Invalid slice specified " + slice; int[] sliceShape = put.shape(); if (Shape.isRowVectorShape(sliceShape)) { return; } else { int[] requiredShape = ArrayUtil.removeIndex(shape(), 0); //no need to compare for scalar; primarily due to shapes either being [1] or length 0 if (put.isScalar()) return; if (isVector() && put.isVector() && put.length() < length()) return; //edge case for column vectors if (Shape.isColumnVectorShape(sliceShape)) return; if (!Shape.shapeEquals(sliceShape, requiredShape) && !Shape.isRowVectorShape(requiredShape) && !Shape.isRowVectorShape(sliceShape)) throw new IllegalStateException(String.format("Invalid shape size of %s . Should have been %s ", Arrays.toString(sliceShape), Arrays.toString(requiredShape))); } }
if (!Shape.shapeEquals(shape(), n.shape())) { return false;
if (!Shape.shapeEquals(shape(), n.shape())) return false;
/** * Create a complex ndarray based on the * real and imaginary * * @param real the real numbers * @param imag the imaginary components * @return the complex */ public static IComplexNDArray createComplex(INDArray real, INDArray imag) { assert Shape.shapeEquals(real.shape(), imag.shape()); IComplexNDArray ret = Nd4j.createComplex(real.shape()); INDArray realLinear = real.linearView(); INDArray imagLinear = imag.linearView(); IComplexNDArray retLinear = ret.linearView(); for (int i = 0; i < ret.length(); i++) { retLinear.putScalar(i, Nd4j.createComplexNumber(realLinear.getDouble(i), imagLinear.getDouble(i))); } logCreationIfNecessary(ret); return ret; }
else { assert Shape.shapeEquals(view.shape(), put.shape()); IComplexNDArray linear = view.linearView(); IComplexNDArray putLinearView = put.linearView();
view.putScalar(i, put.getDouble(i)); else { assert Shape.shapeEquals(view.shape(), put.shape()); INDArray linear = view; INDArray putLinearView = put;