List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:net.michaelpigg.xbeelib.protocol.XbeeAddress.java
private XbeeAddress(byte[] address16, byte[] address64) { this.address_16 = Arrays.copyOf(address16, 2); this.address_64 = Arrays.copyOf(address64, 8); }
From source file:com.opengamma.financial.analytics.LabelledObjectMatrix1D.java
public LabelledObjectMatrix1D(TKey[] keys, Object[] labels, String labelsTitle, TValue[] values, String valuesTitle, TTolerance defaultTolerance) { Validate.notNull(keys, "labels"); Validate.notNull(labels, "label names"); Validate.notNull(values, "values"); final int n = keys.length; Validate.isTrue(n == labels.length, "length of keys array must match length of label names array"); Validate.isTrue(n == values.length, "length of keys array must match length of values array"); _keys = Arrays.copyOf(keys, n); _labels = Arrays.copyOf(labels, n); _labelsTitle = labelsTitle;/*ww w . ja va 2s .com*/ _values = Arrays.copyOf(values, n); _valuesTitle = valuesTitle; _defaultTolerance = defaultTolerance; quickSort(); }
From source file:cn2.CN2.java
public static CNLab2ExerciseOutput solveExercise(CNLab2ExerciseInput in) { double timeMySolution = 0; double timeLibrarySolution = 0; CNLab2ExerciseOutput output = new CNLab2ExerciseOutput(); double[] b = multiplyMatrixByVector(in.s, in.A); output.b = Arrays.copyOf(b, b.length); double[] copyOfS = Arrays.copyOf(in.s, in.s.length); double[][] copyOfA = copyOf(in.A); HHInput hhinput = new HHInput(copyOfA, copyOfS, in.epsilon); output.factorizationResult = factorize(hhinput); double[][] newCopyOfAForQR = copyOf(in.A); double[] copyOfBForQR = Arrays.copyOf(in.s, in.s.length); double[][] BData = new double[copyOfBForQR.length][1]; for (int i = 0; i < copyOfBForQR.length; i++) { BData[i][0] = copyOfBForQR[i];// w w w .ja v a2 s.co m } double start = System.currentTimeMillis(); //using LAML /*la.matrix.DenseMatrix A = new DenseMatrix(copyOfA); la.matrix.DenseMatrix B = new DenseMatrix(BData); la.decomposition.QRDecomposition qRDecomposition = new la.decomposition.QRDecomposition(A); la.matrix.Matrix X = qRDecomposition.solve(B); la.matrix.Matrix R = qRDecomposition.getR(); output.libR = R.getData(); double[] x = new double[X.getRowDimension()]; for(int i=0; i<x.length; i++){x[i] = X.getData()[i][0];} output.xQR = x; */ // using JAMA Jama.Matrix A = new Jama.Matrix(newCopyOfAForQR); String newCopyOfAForQRAsString = cnjava1.CNJava1.printMatrix(newCopyOfAForQR); Jama.Matrix B = new Jama.Matrix(BData); String BAsString = cnjava1.CNJava1.printMatrix(BData); Jama.QRDecomposition decomposition = new Jama.QRDecomposition(A); Jama.Matrix X = decomposition.solve(B); Jama.Matrix residual = A.times(X); String residualAsString = cnjava1.CNJava1.printMatrix(residual.getArray()); double[] x = new double[X.getRowDimension()]; for (int i = 0; i < x.length; i++) { x[i] = residual.getArray()[i][0]; } output.libR = decomposition.getR().getArrayCopy(); output.xQR = x; //using EJML /*LinearSolver linearSolver = new LinearSolverQrHouseCol_D64(); linearSolver.setA(new DenseMatrix64F(copyOfA)); DenseMatrix64F B = new DenseMatrix64F(BData); DenseMatrix64F X = new DenseMatrix64F(); X.setNumCols(1); X.setNumRows(copyOfBForQR.length); linearSolver.solve(B, X); output.xQR = X.getData(); */ //using Apache Commons Math /*RealVector bVector = MatrixUtils.createRealVector(copyOfBForQR); RealMatrix aMatrix = MatrixUtils.createRealMatrix(newCopyOfAForQR); QRDecomposition dec = new QRDecomposition(aMatrix); RealMatrix R = dec.getR(); System.out.println("Lib R: "); System.out.println(R); output.libR = R.getData(); RealVector sol = dec.getSolver().solve(bVector); output.xQR = sol.toArray(); */ timeLibrarySolution = System.currentTimeMillis() - start; double[][] newCopyOfA = copyOf(in.A); double[] newCopyOfB = Arrays.copyOf(b, b.length); start = System.currentTimeMillis(); HHInput hhInputSolve = new HHInput(newCopyOfA, newCopyOfB, in.epsilon); HHOutput hhoutputSolve = factorize(hhInputSolve); System.out.println("My R:"); System.out.println(cnjava1.CNJava1.printMatrix(hhoutputSolve.R)); LinearSystemInput lsi = new LinearSystemInput(); lsi.upperTriangularMatrix = hhoutputSolve.R; lsi.b = hhoutputSolve.bModified; double[] mySolution = solveLinearSystem(lsi); timeMySolution = System.currentTimeMillis() - start; output.xHouseholder = mySolution; output.timeXHouseholder = timeMySolution; output.timeXQR = timeLibrarySolution; computeNorms(output, in); return output; }
From source file:com.linkedin.pinot.perf.ForwardIndexWriterBenchmark.java
public static void convertRawToForwardIndex(File rawFile) throws Exception { List<String> lines = IOUtils.readLines(new FileReader(rawFile)); int totalDocs = lines.size(); int max = Integer.MIN_VALUE; int maxNumberOfMultiValues = Integer.MIN_VALUE; int totalNumValues = 0; int data[][] = new int[totalDocs][]; for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String[] split = line.split(","); totalNumValues = totalNumValues + split.length; if (split.length > maxNumberOfMultiValues) { maxNumberOfMultiValues = split.length; }/*from w ww .ja v a 2 s. c o m*/ data[i] = new int[split.length]; for (int j = 0; j < split.length; j++) { String token = split[j]; int val = Integer.parseInt(token); data[i][j] = val; if (val > max) { max = val; } } } int maxBitsNeeded = (int) Math.ceil(Math.log(max) / Math.log(2)); int size = 2048; int[] offsets = new int[size]; int bitMapSize = 0; File outputFile = new File("output.mv.fwd"); FixedBitMultiValueWriter fixedBitSkipListSCMVWriter = new FixedBitMultiValueWriter(outputFile, totalDocs, totalNumValues, maxBitsNeeded); for (int i = 0; i < totalDocs; i++) { fixedBitSkipListSCMVWriter.setIntArray(i, data[i]); if (i % size == size - 1) { MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(offsets); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); rr1.serialize(dos); dos.close(); // System.out.println("Chunk " + i / size + " bitmap size:" + bos.size()); bitMapSize += bos.size(); } else if (i == totalDocs - 1) { MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(Arrays.copyOf(offsets, i % size)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); rr1.serialize(dos); dos.close(); // System.out.println("Chunk " + i / size + " bitmap size:" + bos.size()); bitMapSize += bos.size(); } } fixedBitSkipListSCMVWriter.close(); System.out.println("Output file size:" + outputFile.length()); System.out.println("totalNumberOfDoc\t\t\t:" + totalDocs); System.out.println("totalNumberOfValues\t\t\t:" + totalNumValues); System.out.println("chunk size\t\t\t\t:" + size); System.out.println("Num chunks\t\t\t\t:" + totalDocs / size); int numChunks = totalDocs / size + 1; int totalBits = (totalNumValues * maxBitsNeeded); int dataSizeinBytes = (totalBits + 7) / 8; System.out.println("Raw data size with fixed bit encoding\t:" + dataSizeinBytes); System.out.println("\nPer encoding size"); System.out.println(); System.out.println("size (offset + length)\t\t\t:" + ((totalDocs * (4 + 4)) + dataSizeinBytes)); System.out.println(); System.out.println("size (offset only)\t\t\t:" + ((totalDocs * (4)) + dataSizeinBytes)); System.out.println(); System.out.println("bitMapSize\t\t\t\t:" + bitMapSize); System.out.println("size (with bitmap)\t\t\t:" + (bitMapSize + (numChunks * 4) + dataSizeinBytes)); System.out.println(); System.out.println("Custom Bitset\t\t\t\t:" + (totalNumValues + 7) / 8); System.out.println("size (with custom bitset)\t\t\t:" + (((totalNumValues + 7) / 8) + (numChunks * 4) + dataSizeinBytes)); }
From source file:com.softenido.cafedark.io.virtual.VirtualFile.java
public VirtualFile(VirtualFile parent, ArchiveEntry child) { String[] parentItems = parent.splitPath(); String[] items = Arrays.copyOf(parentItems, parentItems.length + 1); items[parentItems.length] = child.toString(); this.fs = new ZipVirtualFileSystem(items, child); }
From source file:com.baran.crypto.CryptoDES.java
public byte[] encrypt(File file, String trivia) throws Exception { final MessageDigest md = MessageDigest.getInstance("md5"); // digest the trivia password in UTF-8 final byte[] digestTrivia = md.digest(trivia.getBytes("utf-8")); // truncating digest final byte[] keyBytes = Arrays.copyOf(digestTrivia, 24); for (int j = 0, k = 16; j < 8;) { keyBytes[k++] = keyBytes[j++];/*from ww w.j a va 2 s. c om*/ } // DESede setting final SecretKey key = new SecretKeySpec(keyBytes, "DESede"); // CBC IV setting final IvParameterSpec iv = new IvParameterSpec(new byte[8]); final Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key, iv); String allInOne = FileUtils.readFileToString(file, "utf-8"); final byte[] plainTextBytes = allInOne.getBytes("utf-8"); final byte[] cipherText = cipher.doFinal(plainTextBytes); return cipherText; }
From source file:uk.co.caprica.brue.core.domain.bridge.State.java
@JsonCreator public State(@JsonProperty("on") Boolean on, @JsonProperty("bri") Integer brightness, @JsonProperty("hue") Integer hue, @JsonProperty("sat") Integer saturation, @JsonProperty("xy") Float[] xy, @JsonProperty("ct") Integer ct, @JsonProperty("alert") String alert, @JsonProperty("effect") String effect, @JsonProperty("colormode") String colorMode, @JsonProperty("reachable") Boolean reachable) { this.on = on; this.brightness = brightness; this.hue = hue; this.saturation = saturation; this.xy = xy != null ? Arrays.copyOf(xy, 2) : null; this.ct = ct; this.alert = alert; this.effect = effect; this.colorMode = colorMode; this.reachable = reachable; }
From source file:net.shipilev.fjptrace.util.PairedList.java
public long[] getAllY() { return Arrays.copyOf(k2, index); }
From source file:com.bitbreeds.webrtc.stun.StunAttribute.java
/** * * @return representing this value on the wire *//* w w w . j a v a 2 s . com*/ public byte[] toBytes() { int outLgt = SignalUtil.multipleOfFour(this.length); return SignalUtil.joinBytesArrays(type.toBytes(), SignalUtil.twoBytesFromInt(length), Arrays.copyOf(data, outLgt)); }
From source file:de.tuberlin.uebb.jbop.access.ClassDescriptor.java
/** * Gets the class data as bytearray. * * @return the classData */ public byte[] getClassData() { return Arrays.copyOf(classData, classData.length); }