@Override public float[] toFloatVector() { if(!isVector()) { throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector!"); } return dup().data().asFloat(); }
static boolean Equal(INDArray arr1, INDArray arr2) { return ArrayUtil.equals(arr1.data().asFloat(), arr2.data().asDouble()); }
.append(Arrays.toString(ndarray.shapeInfoDataBuffer().asInt())).append("; Values: ").append(Arrays.toString(ndarray.data().asFloat())).append(";\n");
/** * Returns the float data * for this buffer. * If possible (the offset is 0 representing the whole buffer) * it will return a direct reference to the underlying array * @param buf the ndarray to get the data for * @return the double data for this ndarray */ public static float[] getFloatData(DataBuffer buf) { if (buf.allocationMode() == DataBuffer.AllocationMode.HEAP) { return buf.asFloat(); } else { float[] ret = new float[(int) buf.length()]; for (int i = 0; i < buf.length(); i++) ret[i] = buf.getFloat(i); return ret; } }
protected DataBuffer reallocate(DataBuffer buffer) { int newSize = (int) buffer.length() * 2; DataBuffer newBuffer = Nd4j.createBuffer(newSize); switch (buffer.dataType()) { case INT: newBuffer.setData(buffer.asInt()); break; case DOUBLE: newBuffer.setData(buffer.asDouble()); break; case FLOAT: newBuffer.setData(buffer.asFloat()); break; case HALF: //TODO throw new UnsupportedOperationException(); case COMPRESSED: //TODO throw new UnsupportedOperationException(); default: throw new UnsupportedOperationException(); } return newBuffer; }
/** * Returns the float data * for this ndarray. * If possible (the offset is 0 representing the whole buffer) * it will return a direct reference to the underlying array * @param buf the ndarray to get the data for * @return the float data for this ndarray */ public static float[] getFloatData(INDArray buf) { if (buf.data().dataType() != DataBuffer.Type.FLOAT) throw new IllegalArgumentException("Float data must be obtained from a float buffer"); if (buf.data().allocationMode() == DataBuffer.AllocationMode.HEAP) { return buf.data().asFloat(); } else { float[] ret = new float[(int) buf.length()]; INDArray linear = buf.linearView(); for (int i = 0; i < buf.length(); i++) ret[i] = linear.getFloat(i); return ret; } }
@Override public float[][] toFloatMatrix() { if(!isMatrix()) { throw new ND4JIllegalStateException("Unable to create a 2d array from a non matrix!"); } if (this.rows() > Integer.MAX_VALUE || this.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); float[][] ret = new float[(int) rows()][ (int) columns()]; for(int i = 0; i < ret.length; i++) { ret[i] = getRow(i).dup().data().asFloat(); } return ret; }
on.setValueFor(currentField,tensor.data().asFloat());
float[] floatMask1d = mask1d.data().asFloat(); int currCount = 0; for (int i = 0; i < floatMask1d.length; i++) {
double[] doubles = fourByFiveRandomZeroToOne.data().asDouble(); System.out.println("Array doubles: " + Arrays.toString(doubles)); float[] floats = fourByFiveRandomZeroToOne.data().asFloat(); System.out.println("Array floats: " + Arrays.toString(floats)); int[] ints = fourByFiveRandomZeroToOne.data().asInt();
private int getModelActivationNumber(MultiLayerNetwork model, FeatureMapper modelFeatureMapper) { int numActivations = 0; Layer[] layers = model.getLayers(); INDArray inputFeatures = Nd4j.zeros(1, modelFeatureMapper.numberOfFeatures()); int sum = model.feedForward(inputFeatures, false).stream().mapToInt(indArray -> indArray.data().asFloat().length).sum(); System.out.println("Number of activations: " + sum); return sum; }
private int getModelActivationNumber(MultiLayerNetwork model, FeatureMapper modelFeatureMapper) { int numActivations = 0; Layer[] layers = model.getLayers(); int totalNumParams = 0; INDArray inputFeatures = Nd4j.zeros(1, modelFeatureMapper.numberOfFeatures()); int sum = model.feedForward(inputFeatures, false).stream().mapToInt(indArray -> indArray.data().asFloat().length).sum(); System.out.println("Number of activations: " + sum); return sum; }
private FloatArrayList getModelInternalActivations(INDArray testFeatures) { FloatArrayList floats = new FloatArrayList(); predictiveModel.feedForward(testFeatures).stream().forEach(indArray -> floats.addAll(FloatArrayList.wrap(indArray.data().asFloat()))); return floats; }
@Override protected void sgemm(char Order, char TransA, char TransB, int M, int N, int K, float alpha, INDArray A, int lda, INDArray B, int ldb, float beta, INDArray C, int ldc) { // A = Shape.toOffsetZero(A); // B = Shape.toOffsetZero(B); DataBuffer aData = A.data(); DataBuffer bData = B.data(); float[] cData = getFloatData(C); BLAS.getInstance().sgemm(String.valueOf(TransA),String.valueOf(TransB),M,N,K,alpha,aData.asFloat(),getBlasOffset(A),lda,bData.asFloat(),getBlasOffset(B),ldb,beta,cData,getBlasOffset(C),ldc); setData(cData, C); }
private FloatArrayList getModelInternalActivations(MultiLayerNetwork model, FeatureMapper modelFeatureMapper, BaseInformationRecords.BaseInformation record, int indexOfNewRecordInMinibatch) { INDArray inputFeatures = Nd4j.zeros(1, modelFeatureMapper.numberOfFeatures()); modelFeatureMapper.prepareToNormalize(record,0); modelFeatureMapper.mapFeatures(record, inputFeatures, 0); FloatArrayList floats = new FloatArrayList(); model.feedForward(inputFeatures).stream().forEach(indArray -> floats.addAll(FloatArrayList.wrap(indArray.data().asFloat()))); return floats; }
/** * Scale a complex ndarray * * @param alpha * @param x * @return */ public static IComplexNDArray sscal(IComplexFloat alpha, IComplexNDArray x) { DataTypeValidation.assertFloat(x); NativeBlas.cscal(x.length(), (org.jblas.ComplexFloat) alpha, x.data().asFloat(), x.offset(), x.majorStride()); return x; }
/** * Return the index of the max in the given ndarray * * @param x the ndarray to ge tthe max for * @return */ public static int iamax(IComplexNDArray x) { if (x.data().dataType() == DataBuffer.Type.FLOAT) return NativeBlas.icamax(x.length(), x.data().asFloat(), x.offset(), 1) - 1; else return NativeBlas.izamax(x.length(), x.data().asDouble(), x.offset(), 1) - 1; }
/** * @param x * @return */ public static double asum(IComplexNDArray x) { if (x.data().dataType() == DataBuffer.Type.FLOAT) return NativeBlas.scasum(x.length(), x.data().asFloat(), x.offset(), x.majorStride()); else return NativeBlas.dzasum(x.length(), x.data().asDouble(), x.offset(), x.majorStride()); }
/** * @param x * @return */ public static double asum(INDArray x) { if (x.data().dataType() == DataBuffer.Type.FLOAT) { float sum = BLAS.getInstance().sasum(x.length(), x.data().asFloat(), x.offset(), x.majorStride()); return sum; } else { double sum = BLAS.getInstance().dasum(x.length(), x.data().asDouble(), x.offset(), x.majorStride()); return sum; } }
/** * @param x * @return */ public static double asum(INDArray x) { if (x.data().dataType() == DataBuffer.Type.FLOAT) { float sum = BLAS.getInstance().sasum(x.length(), x.data().asFloat(), x.offset(), x.majorStride()); return sum; } else { double sum = BLAS.getInstance().dasum(x.length(), x.data().asDouble(), x.offset(), x.majorStride()); return sum; } }