Package org.nuiton.math.matrix
Class MatrixFactory
- java.lang.Object
-
- org.nuiton.math.matrix.MatrixFactory
-
public class MatrixFactory extends Object
Cette classe permet de creer des matrices, toutes les creations de matrice doivent etre faite a travers cette classe. Cette classe permet de modifier la representation interne des matrices de facon simple.Created: 11 octobre 2005 20:15:20 CEST
- Version:
- $Revision$ Last update: $Date$ by : $Author$
- Author:
- Benjamin POUSSIN <poussin@codelutin.com>
-
-
Field Summary
Fields Modifier and Type Field Description protected static SemanticMapper
defaultSemanticMapper
protected static Class<?>
defaultSparseVectorClass
protected static int
defaultThresholdSparse
if we try to allocate matrix with more that this threshold, sparse matrix is usedprotected static boolean
defaultUseLazyVector
If true, createVector return all time LazyVector to prevent memory allocation when not necessary.protected static Class<?>
defaultVectorClass
Valeur par defaut si aucun type de Vector n'est donnéprotected Class<?>
sparseVectorClass
protected int
thresholdSparse
protected boolean
useLazyVector
protected Class<?>
vectorClass
-
Constructor Summary
Constructors Modifier Constructor Description protected
MatrixFactory(Class<?> vectorClass, Class<?> sparseVectorClass, int thresholdSparse, boolean useLazyVector)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MatrixND
create(double[] values, int[] dim)
Convert a double array into matrix.MatrixND
create(int[] dim)
MatrixND
create(File file)
Create new Matrix from file.MatrixND
create(Reader reader)
Create new Matrix from file.MatrixND
create(String name, int[] dim)
MatrixND
create(String name, int[] dim, String[] dimNames)
MatrixND
create(String name, int[] dim, String[] dimNames, Vector data)
Create new matrix and force backend to be data.MatrixND
create(String name, List<?>[] semantics)
MatrixND
create(String name, List<?>[] semantics, String[] dimNames)
MatrixND
create(String name, List<?>[] semantics, String[] dimNames, Vector data)
Create new matrix and force backend to be data.MatrixND
create(List<?>[] semantics)
MatrixND
create(MatrixND matrix)
Create new matrix by copying matrix in argumentMatrixND
create(MatrixND matrix, Vector data)
Create new matrix by copying matrix in argument, and force backend to be data.MatrixProxy
createProxy(String name, int[] dim, String[] dimNames, MatrixProvider matrixProvider)
MatrixProxy
createProxy(String name, int[] dim, MatrixProvider matrixProvider)
MatrixProxy
createProxy(String name, List<?>[] semantics, String[] dimNames, MatrixProvider matrixProvider)
MatrixProxy
createProxy(String name, List<?>[] semantics, MatrixProvider matrixProvider)
MatrixProxy
createProxy(List<?>[] semantics, MatrixProvider matrixProvider)
protected Vector
createVector(long length)
cree un nouveau Vector.static Class<?>
getDefaultVectorClass()
static MatrixFactory
getInstance()
Utilise par defautdefaultVectorClass
.static MatrixFactory
getInstance(Class<?> vectorClass)
Retourne une factory utilisant vectorClass comme classe de base a l'implantation des matrices, aussi bien pour les matrices dense que les matrices creuse.static MatrixFactory
getInstance(Class<?> vectorClass, Class<?> sparseVectorClass, int thresholdSparse)
Retourne une factory utilisant, par defaut on utilise les LazyVectorstatic MatrixFactory
getInstance(Class<?> vectorClass, Class<?> sparseVectorClass, int thresholdSparse, boolean useLazyVector)
Retourne une factory utilisant vectorClass comme classe de base a l'implantation des matrices.static SemanticMapper
getSemanticMapper()
Class<?>
getSparseVectorClass()
int
getThresholdSparse()
Class<?>
getVectorClass()
static void
initMatrixFactoryThreadLocal(Class<?> vectorClass, Class<?> sparseVectorClass, int thresholdSparse, boolean useLazyVector)
Initialise une factory pour le thread courant avec le vectorClass passe en parametre.boolean
isUseLazyVector()
MatrixND
matrixId(int size)
Crée une nouvelle matrice identité.static void
removeMatrixFactoryThreadLocal()
Retire la factory pour le thread courantstatic void
setDefaultSparseVectorClass(Class<?> defaultSparseVectorClass)
static void
setDefaultThresholdSparse(int defaultThresholdSparse)
static void
setDefaultUseLazyVector(boolean useLazyVector)
static void
setDefaultVectorClass(Class<?> vectorClass)
static void
setSemanticMapper(SemanticMapper semanticMapper)
-
-
-
Field Detail
-
defaultUseLazyVector
protected static boolean defaultUseLazyVector
If true, createVector return all time LazyVector to prevent memory allocation when not necessary. LazyVector init real vector only when necessary
-
defaultVectorClass
protected static Class<?> defaultVectorClass
Valeur par defaut si aucun type de Vector n'est donné
-
defaultSparseVectorClass
protected static Class<?> defaultSparseVectorClass
-
defaultThresholdSparse
protected static int defaultThresholdSparse
if we try to allocate matrix with more that this threshold, sparse matrix is used
-
vectorClass
protected Class<?> vectorClass
-
sparseVectorClass
protected Class<?> sparseVectorClass
-
thresholdSparse
protected int thresholdSparse
-
useLazyVector
protected boolean useLazyVector
-
defaultSemanticMapper
protected static SemanticMapper defaultSemanticMapper
-
-
Method Detail
-
getVectorClass
public Class<?> getVectorClass()
-
getSparseVectorClass
public Class<?> getSparseVectorClass()
-
getThresholdSparse
public int getThresholdSparse()
-
isUseLazyVector
public boolean isUseLazyVector()
-
setDefaultVectorClass
public static void setDefaultVectorClass(Class<?> vectorClass)
-
setDefaultSparseVectorClass
public static void setDefaultSparseVectorClass(Class<?> defaultSparseVectorClass)
-
setDefaultThresholdSparse
public static void setDefaultThresholdSparse(int defaultThresholdSparse)
-
setDefaultUseLazyVector
public static void setDefaultUseLazyVector(boolean useLazyVector)
-
getDefaultVectorClass
public static Class<?> getDefaultVectorClass()
-
setSemanticMapper
public static void setSemanticMapper(SemanticMapper semanticMapper)
-
getSemanticMapper
public static SemanticMapper getSemanticMapper()
-
getInstance
public static MatrixFactory getInstance(Class<?> vectorClass)
Retourne une factory utilisant vectorClass comme classe de base a l'implantation des matrices, aussi bien pour les matrices dense que les matrices creuse. Par defaut on utilise les LazyVector- Parameters:
vectorClass
- vector class implementation- Returns:
- factory
-
getInstance
public static MatrixFactory getInstance(Class<?> vectorClass, Class<?> sparseVectorClass, int thresholdSparse)
Retourne une factory utilisant, par defaut on utilise les LazyVector- Parameters:
vectorClass
- vector class implementation for dense matrixsparseVectorClass
- vector class implementation for sparse matrixthresholdSparse
- threshold to determine usage of dense or sparse matrix- Returns:
- factory
-
getInstance
public static MatrixFactory getInstance(Class<?> vectorClass, Class<?> sparseVectorClass, int thresholdSparse, boolean useLazyVector)
Retourne une factory utilisant vectorClass comme classe de base a l'implantation des matrices.- Parameters:
vectorClass
- vector class implementation for dense matrixsparseVectorClass
- vector class implementation for sparse matrixthresholdSparse
- threshold to determine usage of dense or sparse matrixuseLazyVector
- if true use LazyVector- Returns:
- factory
-
getInstance
public static MatrixFactory getInstance()
Utilise par defautdefaultVectorClass
. Si une factory a ete initialisee pour le thread local, alors celle-ci sera reutilise, sinon une nouvelle est cree avec le backend par defaut- Returns:
- factory
-
initMatrixFactoryThreadLocal
public static void initMatrixFactoryThreadLocal(Class<?> vectorClass, Class<?> sparseVectorClass, int thresholdSparse, boolean useLazyVector)
Initialise une factory pour le thread courant avec le vectorClass passe en parametre.- Parameters:
vectorClass
- vector class implementation for dense matrixsparseVectorClass
- vector class implementation for sparse matrixthresholdSparse
- threshold to determine usage of dense or sparse matrixuseLazyVector
- if true use LazyVector
-
removeMatrixFactoryThreadLocal
public static void removeMatrixFactoryThreadLocal()
Retire la factory pour le thread courant
-
create
public MatrixND create(File file) throws IOException
Create new Matrix from file. File contains data as describe for export/import CSV ND- Parameters:
file
-- Returns:
- Throws:
IOException
- Since:
- 2.5.2
-
create
public MatrixND create(Reader reader) throws IOException
Create new Matrix from file. File contains data as describe for export/import CSV ND- Parameters:
reader
-- Returns:
- Throws:
IOException
- Since:
- 2.5.2
-
create
public MatrixND create(int[] dim)
-
create
public MatrixND create(double[] values, int[] dim)
Convert a double array into matrix.- Parameters:
values
- The values to fill the matrixdim
- An array representing the dimensions of the matrix- Returns:
- a 2D matrix filled with the values, null if the dimension is more than 2
-
create
public MatrixND create(String name, int[] dim, String[] dimNames, Vector data)
Create new matrix and force backend to be data.- Parameters:
name
- matrix's name (can be null)dim
- matrix's dimension (must be provided)dimNames
- dimensions' name (can be null)data
- backend used to new matrix- Returns:
- new Matrix with specified backend
-
create
public MatrixND create(String name, List<?>[] semantics, String[] dimNames, Vector data)
Create new matrix and force backend to be data.- Parameters:
name
- matrix's name (can be null)semantics
- semantiques (must be provided)dimNames
- dimensions' name (can be null)data
- backend used to new matrix- Returns:
- new Matrix with specified backend
-
create
public MatrixND create(MatrixND matrix)
Create new matrix by copying matrix in argument- Parameters:
matrix
-- Returns:
-
create
public MatrixND create(MatrixND matrix, Vector data)
Create new matrix by copying matrix in argument, and force backend to be data.- Parameters:
matrix
- matrix to copieddata
- backend used to new matrix
-
matrixId
public MatrixND matrixId(int size)
Crée une nouvelle matrice identité. Une matrice identité est une matrice à 2 dimensions dont tous les éléments de la diagonal vaut 1- Parameters:
size
- la taille de la matrice- Returns:
- une nouvelle matrice identité
-
createVector
protected Vector createVector(long length)
cree un nouveau Vector. Si la taille demandee est inferieur au seuil alors on cree une matrice plaine, sinon on cree une matrice creuse.- Parameters:
length
-- Returns:
-
createProxy
public MatrixProxy createProxy(List<?>[] semantics, MatrixProvider matrixProvider)
-
createProxy
public MatrixProxy createProxy(String name, int[] dim, MatrixProvider matrixProvider)
-
createProxy
public MatrixProxy createProxy(String name, int[] dim, String[] dimNames, MatrixProvider matrixProvider)
-
createProxy
public MatrixProxy createProxy(String name, List<?>[] semantics, MatrixProvider matrixProvider)
-
createProxy
public MatrixProxy createProxy(String name, List<?>[] semantics, String[] dimNames, MatrixProvider matrixProvider)
-
-