⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 array2float.java

📁 a molecular graph kernel based on iterative graph similarity and optimal assignments
💻 JAVA
字号:
/** * ISOAK - Iterative similarity optimal assignment kernel. *  * Written by Matthias Rupp 2006-2007. * Copyright (c) 2006-2007, Matthias Rupp, Ewgenij Proschak, Gisbert Schneider. *  * All rights reserved. *  * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: *  *  * The above copyright notice, this permission notice and the following disclaimers *    shall be included in all copies or substantial portions of this software. *  * The names of the authors may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. *  * Please cite *  * Matthias Rupp, Ewgenij Proschak, Gisbert Schneider: * A Kernel Approach to Molecular Similarity Based on Iterative Graph Similarity, * Journal of Chemical Information and Molecular Modeling, 47(6): 2280-2286, 2007,  * DOI http://dx.doi.org/10.1021/ci700274r. * * if you use this software. */package info.mrupp.isoak1;/**  * Two-dimensional array of single precision floating point numbers. *  * Optimized for speed (memory is never released to save on allocations). */public class Array2Float {	protected int rows, cols;	protected float[] data;		// Constructors.    /** Creates an empty array. */	public Array2Float() {		rows = 0; cols = 0;		data = new float[0];	}	    /** Creates an array of given size. */	public Array2Float(int rows, int cols) throws NegativeArraySizeException {		this.rows = rows; this.cols = cols;		data = new float[rows*cols]; 	}	    /** Creates a copy from a rectangular built-in array. */	public Array2Float(float[][] array) throws IllegalArgumentException { 		checkArrayRectangular(array);		rows = array.length; cols = array[0].length;		data = new float[rows*cols];		for (int r = rows; --r >= 0; ) for (int c = cols; --c >= 0; ) data[sub2ind(r,c)] = array[r][c];	}	    /** Creates a copy from a rectangular built-in array. */	public Array2Float(float[][] array, boolean transpose) throws IllegalArgumentException { 		checkArrayRectangular(array);		if (transpose) { rows = array[0].length; cols = array.length; } else { rows = array.length; cols = array[0].length; }		data = new float[rows*cols];		for (int r = rows; --r >= 0; ) for (int c = cols; --c >= 0; ) data[sub2ind(r,c)] = (transpose ? array[c][r] : array[r][c]);	}	    /** Creates a copy of another Array2Float. */	public Array2Float(Array2Float array) {		rows = array.rows(); cols = array.cols();		data = new float[rows*cols];		for (int i = array.elems(); --i >= 0; ) data[i] = array.get(i);	}    /** Creates a copy of another Array2Float. */	public Array2Float(Array2Float array, boolean transpose) {		if (transpose) { rows = array.cols(); cols = array.rows(); } else { rows = array.rows(); cols = array.cols(); }		data = new float[rows*cols];		for (int r = rows; --r >= 0; ) for (int c = cols; --c >= 0; ) data[sub2ind(r,c)] = (transpose ? array.get(c,r) : array.get(r,c));	}		// Public interface.    /** The number of rows. */    public int rows() { return rows; }        /** The number of columns. */	public int cols() { return cols; }        /** The total number of elements in the array. */	public int elems() { return rows*cols; }	    /** Reads an element using a single index. */	public float get(int index) { return data[index]; }        /** Reads an element using row and column indices. */	public float get(int row, int col) { return data[sub2ind(row, col)]; }	    /** Writes an element using a single index. */	public void set(int index, float value) { data[index] = value; }        /** Writes an element using row and column indices. */	public void set(int row, int col, float value) { data[sub2ind(row, col)] = value; }	    /** Changes the dimensions of the array.     *      * Content is lost. New memory is only allocated if the number of elements grows.     */	public void redim(int rows, int cols) {		if (rows*cols > data.length) data = new float[rows*cols];  // Acquire more memory only if necessary.		this.rows = rows; this.cols = cols;	}		// Internals.        /* Converts row & column based indices into a one-dimensional index for internal use. */	protected int sub2ind(int row, int col) {		assert 0 <= row && row < rows && 0 <= col && col < cols; 		return col*rows + row; 	}	    /* Checks if an array of arrays is rectangular. */	private void checkArrayRectangular(float[][] array) {		for (int row = array.length; --row > 0; ) if (array[row].length != array[row-1].length) throw new IllegalArgumentException("Array2Float: float[][] passed to constructor is not rectangular."); 	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -