All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ejml.data.D1Matrix64F Maven / Gradle / Ivy

/*
 * Copyright (c) 2009-2013, Peter Abeles. All Rights Reserved.
 *
 * This file is part of Efficient Java Matrix Library (EJML).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ejml.data;

import org.ejml.alg.dense.mult.MatrixDimensionException;


/**
 * A generic abstract class for matrices whose data is stored in a single 1D array of doubles.  The
 * format of the elements in this array is not specified.  For example row major, column major,
 * and block row major are all common formats.
 *
 * @author Peter Abeles
 */
public abstract class D1Matrix64F extends ReshapeMatrix64F {
    /**
     * Where the raw data for the matrix is stored.  The format is type dependent.
     */
    public double[] data;

    /**
     * Used to get a reference to the internal data.
     *
     * @return Reference to the matrix's data.
     */
    public double[] getData() {
        return data;
    }

	/**
	 * Changes the internal array reference.
	 */
	public void setData( double[] data ) {
		this.data = data;
	}

    /**
     * Returns the internal array index for the specified row and column.
     *
     * @param row Row index.
     * @param col Column index.
     * @return Internal array index.
     */
    public abstract int getIndex( int row, int col );

    /**
     * Sets the value of this matrix to be the same as the value of the provided matrix.  Both
     * matrices must have the same shape:
*
* aij = bij
*
* * @param b The matrix that this matrix is to be set equal to. */ public void set( D1Matrix64F b ) { if( numRows != b.numRows || numCols != b.numCols ) { throw new MatrixDimensionException("The two matrices do not have compatible shapes."); } int dataLength = b.getNumElements(); System.arraycopy(b.data, 0, this.data, 0, dataLength); } /** * Returns the value of the matrix at the specified internal array index. The element at which row and column * returned by this function depends upon the matrix's internal structure, e.g. row-major, column-major, or block. * * @param index Internal array index. * @return Value at the specified index. */ public double get( int index ) { return data[index]; } /** * Sets the element's value at the specified index. The element at which row and column * modified by this function depends upon the matrix's internal structure, e.g. row-major, column-major, or block. * * @param index Index of element that is to be set. * @param val The new value of the index. */ public double set( int index , double val ) { // See benchmarkFunctionReturn. Pointless return does not degrade performance. Tested on JDK 1.6.0_21 return data[index] = val; } /** *

* Adds the specified value to the internal data array at the specified index.
*
* Equivalent to: this.data[index] += val; *

* *

* Intended for use in highly optimized code. The row/column coordinate of the modified element is * dependent upon the matrix's internal structure. *

* * @param index The index which is being modified. * @param val The value that is being added. */ public double plus( int index , double val ) { // See benchmarkFunctionReturn. Pointless return does not degrade performance. Tested on JDK 1.6.0_21 return data[index] += val; } /** *

* Subtracts the specified value to the internal data array at the specified index.
*
* Equivalent to: this.data[index] -= val; *

* *

* Intended for use in highly optimized code. The row/column coordinate of the modified element is * dependent upon the matrix's internal structure. *

* * @param index The index which is being modified. * @param val The value that is being subtracted. */ public double minus( int index , double val ) { // See benchmarkFunctionReturn. Pointless return does not degrade performance. Tested on JDK 1.6.0_21 return data[index] -= val; } /** *

* Multiplies the specified value to the internal data array at the specified index.
*
* Equivalent to: this.data[index] *= val; *

* *

* Intended for use in highly optimized code. The row/column coordinate of the modified element is * dependent upon the matrix's internal structure. *

* * @param index The index which is being modified. * @param val The value that is being multiplied. */ public double times( int index , double val ) { // See benchmarkFunctionReturn. Pointless return does not degrade performance. Tested on JDK 1.6.0_21 return data[index] *= val; } /** *

* Divides the specified value to the internal data array at the specified index.
*
* Equivalent to: this.data[index] /= val; *

* *

* Intended for use in highly optimized code. The row/column coordinate of the modified element is * dependent upon the matrix's internal structure. *

* * @param index The index which is being modified. * @param val The value that is being divided. */ public double div( int index , double val ) { // See benchmarkFunctionReturn. Pointless return does not degrade performance. Tested on JDK 1.6.0_21 return data[index] /= val; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy