Package cc.mallet.types
Class SparseMatrixn
- java.lang.Object
-
- cc.mallet.types.SparseMatrixn
-
- All Implemented Interfaces:
ConstantMatrix
,Matrix
,java.io.Serializable
,java.lang.Cloneable
public class SparseMatrixn extends java.lang.Object implements Matrix, java.lang.Cloneable, java.io.Serializable
Implementation of Matrix that allows arbitrary number of dimensions. This implementation simply uses a flat array. Created: Tue Sep 16 14:52:37 2003- Version:
- $Id: SparseMatrixn.java,v 1.1 2007/10/22 21:37:39 mccallum Exp $
- Author:
- Charles Sutton
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SparseMatrixn(double[] vals)
Create a 1-d dense matrix with the given values.SparseMatrixn(int[] szs)
Create a dense matrix with the given dimensions.SparseMatrixn(int[] szs, double[] vals)
SparseMatrixn(int[] szs, int[] idxs, double[] vals)
Create a sparse matrix with the given dimensions and the given values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
absNorm()
double
absNormalize()
java.lang.Object
clone()
ConstantMatrix
cloneMatrix()
void
divideEquals(double factor)
double
dotProduct(ConstantMatrix m)
void
elementwiseDivideEquals(ConstantMatrix m)
void
elementwiseDivideEquals(ConstantMatrix m, double factor)
void
elementwiseTimesEquals(ConstantMatrix m)
void
elementwiseTimesEquals(ConstantMatrix m, double factor)
boolean
equals(java.lang.Object o)
void
equalsPlus(double factor, ConstantMatrix m)
int
getDimensions(int[] szs)
int[]
getIndices()
Returns an array of all the present indices.int
getNumDimensions()
int
hashCode()
void
incrementSingleValue(int i, double delta)
int
indexAtLocation(int location)
double
infinityNorm()
double
infinityNormalize()
boolean
isNaN()
int
location(int index)
int
numLocations()
double
oneNorm()
double
oneNormalize()
void
plusEquals(ConstantMatrix m)
void
plusEquals(ConstantMatrix m, double factor)
void
print()
void
set(ConstantMatrix m)
void
setAll(double v)
void
setSingleValue(int i, double value)
void
setValue(int[] indices, double value)
void
setValueAtLocation(int location, double value)
void
setWithAddend(ConstantMatrix m, double addend)
void
setWithFactor(ConstantMatrix m, double factor)
int
singleIndex(int[] indices)
static int
singleIndex(int[] szs, int[] indices)
int
singleSize()
void
singleToIndices(int single, int[] indices)
double
singleValue(int i)
void
timesEquals(double factor)
double[]
toArray()
Returns a one-dimensional array representation of the matrix.double
twoNorm()
double
twoNormalize()
double
value(int[] indices)
double
valueAtLocation(int location)
-
-
-
Constructor Detail
-
SparseMatrixn
public SparseMatrixn(double[] vals)
Create a 1-d dense matrix with the given values.
-
SparseMatrixn
public SparseMatrixn(int[] szs)
Create a dense matrix with the given dimensions.- Parameters:
szs
- An array containing the maximum for each dimension.
-
SparseMatrixn
public SparseMatrixn(int[] szs, double[] vals)
-
SparseMatrixn
public SparseMatrixn(int[] szs, int[] idxs, double[] vals)
Create a sparse matrix with the given dimensions and the given values.- Parameters:
szs
- An array containing the maximum for each dimension.idxs
- An array containing the single index for each entry of the matrix. A single index is an integer computed from the indices of each dimension. as returned byMatrixn.singleIndex(int[])
.vals
- A flat array of the entries of the matrix, in row-major order.
-
-
Method Detail
-
getNumDimensions
public int getNumDimensions()
- Specified by:
getNumDimensions
in interfaceConstantMatrix
-
getDimensions
public int getDimensions(int[] szs)
- Specified by:
getDimensions
in interfaceConstantMatrix
-
value
public double value(int[] indices)
- Specified by:
value
in interfaceConstantMatrix
-
setValue
public void setValue(int[] indices, double value)
-
getIndices
public int[] getIndices()
Returns an array of all the present indices. Callers must not modify the return value.
-
cloneMatrix
public ConstantMatrix cloneMatrix()
- Specified by:
cloneMatrix
in interfaceConstantMatrix
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
singleIndex
public int singleIndex(int[] indices)
- Specified by:
singleIndex
in interfaceConstantMatrix
-
singleIndex
public static int singleIndex(int[] szs, int[] indices)
-
singleToIndices
public void singleToIndices(int single, int[] indices)
- Specified by:
singleToIndices
in interfaceConstantMatrix
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toArray
public double[] toArray()
Returns a one-dimensional array representation of the matrix. Caller must not modify the return value.- Returns:
- An array of the values where index 0 is the major index, etc.
-
singleValue
public double singleValue(int i)
- Specified by:
singleValue
in interfaceConstantMatrix
-
singleSize
public int singleSize()
- Specified by:
singleSize
in interfaceConstantMatrix
-
numLocations
public int numLocations()
- Specified by:
numLocations
in interfaceConstantMatrix
-
location
public int location(int index)
- Specified by:
location
in interfaceConstantMatrix
-
valueAtLocation
public double valueAtLocation(int location)
- Specified by:
valueAtLocation
in interfaceConstantMatrix
-
setValueAtLocation
public void setValueAtLocation(int location, double value)
- Specified by:
setValueAtLocation
in interfaceMatrix
-
indexAtLocation
public int indexAtLocation(int location)
- Specified by:
indexAtLocation
in interfaceConstantMatrix
-
dotProduct
public double dotProduct(ConstantMatrix m)
- Specified by:
dotProduct
in interfaceConstantMatrix
-
absNorm
public double absNorm()
- Specified by:
absNorm
in interfaceConstantMatrix
-
oneNorm
public double oneNorm()
- Specified by:
oneNorm
in interfaceConstantMatrix
-
twoNorm
public double twoNorm()
- Specified by:
twoNorm
in interfaceConstantMatrix
-
infinityNorm
public double infinityNorm()
- Specified by:
infinityNorm
in interfaceConstantMatrix
-
print
public void print()
- Specified by:
print
in interfaceConstantMatrix
-
isNaN
public boolean isNaN()
- Specified by:
isNaN
in interfaceConstantMatrix
-
setSingleValue
public void setSingleValue(int i, double value)
- Specified by:
setSingleValue
in interfaceMatrix
-
incrementSingleValue
public void incrementSingleValue(int i, double delta)
- Specified by:
incrementSingleValue
in interfaceMatrix
-
set
public void set(ConstantMatrix m)
-
setWithAddend
public void setWithAddend(ConstantMatrix m, double addend)
- Specified by:
setWithAddend
in interfaceMatrix
-
setWithFactor
public void setWithFactor(ConstantMatrix m, double factor)
- Specified by:
setWithFactor
in interfaceMatrix
-
plusEquals
public void plusEquals(ConstantMatrix m)
- Specified by:
plusEquals
in interfaceMatrix
-
plusEquals
public void plusEquals(ConstantMatrix m, double factor)
- Specified by:
plusEquals
in interfaceMatrix
-
equalsPlus
public void equalsPlus(double factor, ConstantMatrix m)
- Specified by:
equalsPlus
in interfaceMatrix
-
timesEquals
public void timesEquals(double factor)
- Specified by:
timesEquals
in interfaceMatrix
-
elementwiseTimesEquals
public void elementwiseTimesEquals(ConstantMatrix m)
- Specified by:
elementwiseTimesEquals
in interfaceMatrix
-
elementwiseTimesEquals
public void elementwiseTimesEquals(ConstantMatrix m, double factor)
- Specified by:
elementwiseTimesEquals
in interfaceMatrix
-
divideEquals
public void divideEquals(double factor)
- Specified by:
divideEquals
in interfaceMatrix
-
elementwiseDivideEquals
public void elementwiseDivideEquals(ConstantMatrix m)
- Specified by:
elementwiseDivideEquals
in interfaceMatrix
-
elementwiseDivideEquals
public void elementwiseDivideEquals(ConstantMatrix m, double factor)
- Specified by:
elementwiseDivideEquals
in interfaceMatrix
-
oneNormalize
public double oneNormalize()
- Specified by:
oneNormalize
in interfaceMatrix
-
twoNormalize
public double twoNormalize()
- Specified by:
twoNormalize
in interfaceMatrix
-
absNormalize
public double absNormalize()
- Specified by:
absNormalize
in interfaceMatrix
-
infinityNormalize
public double infinityNormalize()
- Specified by:
infinityNormalize
in interfaceMatrix
-
-