001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.core.doublematrix.stub; 025 026 import org.ujmp.core.Matrix; 027 import org.ujmp.core.calculation.DivideScalar; 028 import org.ujmp.core.calculation.MinusMatrix; 029 import org.ujmp.core.calculation.MinusScalar; 030 import org.ujmp.core.calculation.Mtimes; 031 import org.ujmp.core.calculation.PlusMatrix; 032 import org.ujmp.core.calculation.PlusScalar; 033 import org.ujmp.core.calculation.TimesMatrix; 034 import org.ujmp.core.calculation.TimesScalar; 035 import org.ujmp.core.calculation.Transpose; 036 import org.ujmp.core.doublematrix.DenseDoubleMatrix2D; 037 import org.ujmp.core.doublematrix.factory.DefaultDenseDoubleMatrix2DFactory; 038 import org.ujmp.core.doublematrix.factory.DenseDoubleMatrix2DFactory; 039 import org.ujmp.core.exceptions.MatrixException; 040 import org.ujmp.core.util.CoordinateIterator2D; 041 042 public abstract class AbstractDenseDoubleMatrix2D extends AbstractDenseDoubleMatrix implements 043 DenseDoubleMatrix2D { 044 045 public static DenseDoubleMatrix2DFactory factory = new DefaultDenseDoubleMatrix2DFactory(); 046 047 private static final long serialVersionUID = 4518790844453035022L; 048 049 public final Iterable<long[]> allCoordinates() { 050 return new CoordinateIterator2D(getSize()); 051 } 052 053 public final double getDouble(long... coordinates) { 054 return getDouble(coordinates[ROW], coordinates[COLUMN]); 055 } 056 057 public final void setDouble(double value, long... coordinates) { 058 setDouble(value, coordinates[ROW], coordinates[COLUMN]); 059 } 060 061 public final Double getObject(long row, long column) throws MatrixException { 062 return getDouble(row, column); 063 } 064 065 public final void setObject(Double o, long row, long column) throws MatrixException { 066 setDouble(o, row, column); 067 } 068 069 public final Double getObject(int row, int column) throws MatrixException { 070 return getDouble(row, column); 071 } 072 073 public final void setObject(Double o, int row, int column) throws MatrixException { 074 setDouble(o, row, column); 075 } 076 077 public double getAsDouble(long row, long column) { 078 return getDouble(row, column); 079 } 080 081 public double getAsDouble(int row, int column) { 082 return getDouble(row, column); 083 } 084 085 public void setAsDouble(double value, int row, int column) { 086 setDouble(value, row, column); 087 } 088 089 public void setAsDouble(double value, long row, long column) { 090 setDouble(value, row, column); 091 } 092 093 public Matrix mtimes(Matrix m2) { 094 if (m2 instanceof DenseDoubleMatrix2D) { 095 final DenseDoubleMatrix2D result = factory.zeros(getRowCount(), m2.getColumnCount()); 096 Mtimes.DENSEDOUBLEMATRIX2D.calc(this, (DenseDoubleMatrix2D) m2, result); 097 return result; 098 } else { 099 return super.mtimes(m2); 100 } 101 } 102 103 public Matrix times(Matrix m2) { 104 if (m2 instanceof DenseDoubleMatrix2D) { 105 final DenseDoubleMatrix2D result = factory.zeros(getRowCount(), getColumnCount()); 106 TimesMatrix.DENSEDOUBLEMATRIX2D.calc(this, (DenseDoubleMatrix2D) m2, result); 107 return result; 108 } else { 109 return super.times(m2); 110 } 111 } 112 113 public Matrix divide(Matrix m2) { 114 if (m2 instanceof DenseDoubleMatrix2D) { 115 final DenseDoubleMatrix2D result = factory.zeros(getRowCount(), getColumnCount()); 116 DenseDoubleMatrix2D.divideMatrix.calc(this, (DenseDoubleMatrix2D) m2, result); 117 return result; 118 } else { 119 return super.divide(m2); 120 } 121 } 122 123 public Matrix plus(Matrix m2) { 124 if (m2 instanceof DenseDoubleMatrix2D) { 125 final DenseDoubleMatrix2D result = getFactory().zeros(getRowCount(), getColumnCount()); 126 PlusMatrix.DENSEDOUBLEMATRIX2D.calc(this, (DenseDoubleMatrix2D) m2, result); 127 return result; 128 } else { 129 return super.plus(m2); 130 } 131 } 132 133 public Matrix minus(Matrix m2) { 134 if (m2 instanceof DenseDoubleMatrix2D) { 135 final DenseDoubleMatrix2D result = getFactory().zeros(getRowCount(), getColumnCount()); 136 MinusMatrix.DENSEDOUBLEMATRIX2D.calc(this, (DenseDoubleMatrix2D) m2, result); 137 return result; 138 } else { 139 return super.minus(m2); 140 } 141 } 142 143 public Matrix minus(double v) { 144 final DenseDoubleMatrix2D result = getFactory().zeros(getRowCount(), getColumnCount()); 145 MinusScalar.DENSEDOUBLEMATRIX2D.calc(this, v, result); 146 return result; 147 } 148 149 public Matrix plus(double v) { 150 final DenseDoubleMatrix2D result = getFactory().zeros(getRowCount(), getColumnCount()); 151 PlusScalar.DENSEDOUBLEMATRIX2D.calc(this, v, result); 152 return result; 153 } 154 155 public Matrix times(double v) { 156 final DenseDoubleMatrix2D result = getFactory().zeros(getRowCount(), getColumnCount()); 157 TimesScalar.DENSEDOUBLEMATRIX2D.calc(this, v, result); 158 return result; 159 } 160 161 public Matrix divide(double v) { 162 final DenseDoubleMatrix2D result = getFactory().zeros(getRowCount(), getColumnCount()); 163 DivideScalar.DENSEDOUBLEMATRIX2D.calc(this, v, result); 164 return result; 165 } 166 167 public Matrix transpose() { 168 final DenseDoubleMatrix2D result = getFactory().zeros(getColumnCount(), getRowCount()); 169 Transpose.DENSEDOUBLEMATRIX2D.calc(this, result); 170 return result; 171 } 172 173 public DenseDoubleMatrix2DFactory getFactory() { 174 return factory; 175 } 176 177 }