![JAR search and dependency download from the Maven repository](/logo.png)
gov.sandia.cognition.math.matrix.custom.CustomSparseMatrixFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cognitive-foundry Show documentation
Show all versions of cognitive-foundry Show documentation
A single jar with all the Cognitive Foundry components.
/*
* File: SparseMatrixFactoryOptimized.java
* Authors: Jeremy D. Wendt
* Company: Sandia National Laboratories
* Project: Cognitive Foundry
*
* Copyright 2015, Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
* or on behalf of the U.S. Government. Export of this program may require a
* license from the United States Government. See CopyrightHistory.txt for
* complete details.
*/
package gov.sandia.cognition.math.matrix.custom;
import gov.sandia.cognition.math.matrix.Matrix;
import gov.sandia.cognition.math.matrix.MatrixFactory;
/**
* Factory for Sparse Matrices.
*
* @author Jeremy D. Wendt
* @since 4.0.0
*/
public class CustomSparseMatrixFactory
extends MatrixFactory
{
/** An instance of this class. */
public static CustomSparseMatrixFactory INSTANCE = new CustomSparseMatrixFactory();
/**
* {@inheritDoc}
*
* NOTE: Returned matrix is Yale format if m is Diagonal, Dense, or Sparse
* in Yale format. Is sparse row if m is Sparse and in sparse row format.
*
* @return {@inheritDoc}
*/
@Override
final public SparseMatrix copyMatrix(
final Matrix m)
{
if (m instanceof SparseMatrix)
{
return new SparseMatrix((SparseMatrix) m);
}
else if (m instanceof DenseMatrix)
{
return new SparseMatrix((DenseMatrix) m);
}
else if (m instanceof DiagonalMatrix)
{
return new SparseMatrix((DiagonalMatrix) m);
}
// I have to handle other matrix types
SparseMatrix result = new SparseMatrix(m.getNumRows(), m.getNumColumns());
result.convertFromVector(m.convertToVector());
return result;
}
/**
* {@inheritDoc}
*
* NOTE: Returned matrix is sparse row format.
*
* @return {@inheritDoc}
*/
@Override
final public SparseMatrix createMatrix(
final int numRows,
final int numColumns)
{
return new SparseMatrix(numRows, numColumns);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy