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.longmatrix.impl; 025 026 import org.ujmp.core.Matrix; 027 import org.ujmp.core.exceptions.MatrixException; 028 import org.ujmp.core.longmatrix.stub.AbstractDenseLongMatrix2D; 029 030 public class SimpleDenseLongMatrix2D extends AbstractDenseLongMatrix2D { 031 private static final long serialVersionUID = 2888746188860361425L; 032 033 private long[][] values = null; 034 035 public SimpleDenseLongMatrix2D(Matrix m) throws MatrixException { 036 if (m instanceof SimpleDenseLongMatrix2D) { 037 long[][] v = ((SimpleDenseLongMatrix2D) m).values; 038 this.values = new long[v.length][v[0].length]; 039 for (int r = v.length; --r >= 0;) { 040 for (int c = v[0].length; --c >= 0;) { 041 values[r][c] = v[r][c]; 042 } 043 } 044 } else { 045 values = new long[(int) m.getRowCount()][(int) m.getColumnCount()]; 046 for (long[] c : m.allCoordinates()) { 047 setAsLong(m.getAsLong(c), c); 048 } 049 } 050 } 051 052 public SimpleDenseLongMatrix2D(long[]... v) { 053 this.values = v; 054 } 055 056 public SimpleDenseLongMatrix2D(long... size) { 057 values = new long[(int) size[ROW]][(int) size[COLUMN]]; 058 } 059 060 public long[] getSize() { 061 return new long[] { values.length, values.length == 0 ? 0 : values[0].length }; 062 } 063 064 065 public long getRowCount() { 066 return values.length; 067 } 068 069 070 public long getColumnCount() { 071 return values.length == 0 ? 0 : values[0].length; 072 } 073 074 public long getLong(long row, long column) { 075 return values[(int) row][(int) column]; 076 } 077 078 public void setLong(long value, long row, long column) { 079 values[(int) row][(int) column] = value; 080 } 081 082 public long getLong(int row, int column) { 083 return values[row][column]; 084 } 085 086 public void setLong(long value, int row, int column) { 087 values[row][column] = value; 088 } 089 090 091 public final Matrix transpose() { 092 long[][] result = new long[values[0].length][values.length]; 093 for (int r = result.length; --r >= 0;) { 094 for (int c = result[0].length; --c >= 0;) { 095 result[r][c] = values[c][r]; 096 } 097 } 098 return new SimpleDenseLongMatrix2D(result); 099 } 100 101 }