Java examples for java.lang:Math Vector
Append the vector u to the vector v and return the result
/*//from w w w .j av a 2s . co m * Java Information Dynamics Toolkit (JIDT) * Copyright (C) 2012, Joseph T. Lizier * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; public class Main { /** * Append the vector u to the vector v and return the result * * @param v vector 1 * @param u vector 2 * @return [v, u] appended result */ public static double[] append(double[] v, double[] u) { double[] result = new double[v.length + u.length]; System.arraycopy(v, 0, result, 0, v.length); System.arraycopy(u, 0, result, v.length, u.length); return result; } /** * Append the vector u to the vector v and return the result * * @param v vector 1 * @param u vector 2 * @return [v, u] appended result */ public static int[] append(int[] v, int[] u) { int[] result = new int[v.length + u.length]; System.arraycopy(v, 0, result, 0, v.length); System.arraycopy(u, 0, result, v.length, u.length); return result; } /** * Copies all rows and columns between two double arrays * * @param src * @param dest */ public static void arrayCopy(double[][] src, double[][] dest) { for (int r = 0; r < src.length; r++) { System.arraycopy(src[r], 0, dest[r], 0, src[r].length); } } /** * Copies all rows and columns between two double arrays * * @param src * @param dest */ public static double[][] arrayCopy(double[][] src) { double[][] dest = new double[src.length][]; for (int r = 0; r < src.length; r++) { dest[r] = new double[src[r].length]; System.arraycopy(src[r], 0, dest[r], 0, src[r].length); } return dest; } /** * Copies the required rows and columns between two * double arrays * * @param src * @param srcStartRow * @param srcStartCol * @param dest * @param destStartRow * @param destStartCol * @param rows * @param cols */ public static void arrayCopy(double[][] src, int srcStartRow, int srcStartCol, double[][] dest, int destStartRow, int destStartCol, int rows, int cols) { for (int r = 0; r < rows; r++) { System.arraycopy(src[srcStartRow + r], srcStartCol, dest[destStartRow + r], destStartCol, cols); } } /** * Copies all rows and columns between two int arrays * * @param src * @param dest */ public static void arrayCopy(int[][] src, int[][] dest) { for (int r = 0; r < src.length; r++) { System.arraycopy(src[r], 0, dest[r], 0, src[r].length); } } /** * Copies the required rows and columns between two * double arrays * * @param src * @param srcStartRow * @param srcStartCol * @param dest * @param destStartRow * @param destStartCol * @param rows * @param cols */ public static void arrayCopy(int[][] src, int srcStartRow, int srcStartCol, int[][] dest, int destStartRow, int destStartCol, int rows, int cols) { for (int r = 0; r < rows; r++) { System.arraycopy(src[srcStartRow + r], srcStartCol, dest[destStartRow + r], destStartCol, cols); } } }