├── .github └── workflows │ ├── build.yml │ ├── javadoc-gh-pages.yml │ └── maven-publish.yml ├── .gitignore ├── LICENSE ├── README.md ├── configs ├── CmDeMatMult.properties ├── GeneralConfigs.properties └── ReDeMatMult.properties ├── figures ├── intelij_doc_render.png └── latex_in_javadoc.png ├── pom.xml ├── qodana.yaml ├── scripts ├── USAGE.md └── convert_latex.py └── src ├── main └── java │ └── org │ └── flag4j │ ├── arrays │ ├── IntTuple.java │ ├── Pair.java │ ├── Shape.java │ ├── SmartMatrix.java │ ├── SparseMatrixData.java │ ├── SparseTensorData.java │ ├── SparseVectorData.java │ ├── Triple.java │ ├── Tuple.java │ ├── backend │ │ ├── AbstractTensor.java │ │ ├── MatrixMixin.java │ │ ├── VectorMixin.java │ │ ├── field_arrays │ │ │ ├── AbstractCooFieldMatrix.java │ │ │ ├── AbstractCooFieldTensor.java │ │ │ ├── AbstractCooFieldVector.java │ │ │ ├── AbstractCsrFieldMatrix.java │ │ │ ├── AbstractDenseFieldMatrix.java │ │ │ ├── AbstractDenseFieldTensor.java │ │ │ ├── AbstractDenseFieldVector.java │ │ │ ├── FieldTensorMixin.java │ │ │ └── TensorOverField.java │ │ ├── primitive_arrays │ │ │ ├── AbstractDenseDoubleTensor.java │ │ │ └── AbstractDoubleTensor.java │ │ ├── ring_arrays │ │ │ ├── AbstractCooRingMatrix.java │ │ │ ├── AbstractCooRingTensor.java │ │ │ ├── AbstractCooRingVector.java │ │ │ ├── AbstractCsrRingMatrix.java │ │ │ ├── AbstractDenseRingMatrix.java │ │ │ ├── AbstractDenseRingTensor.java │ │ │ ├── AbstractDenseRingVector.java │ │ │ ├── RingTensorMixin.java │ │ │ └── TensorOverRing.java │ │ ├── semiring_arrays │ │ │ ├── AbstractCooSemiringMatrix.java │ │ │ ├── AbstractCooSemiringTensor.java │ │ │ ├── AbstractCooSemiringVector.java │ │ │ ├── AbstractCsrSemiringMatrix.java │ │ │ ├── AbstractDenseSemiringMatrix.java │ │ │ ├── AbstractDenseSemiringTensor.java │ │ │ ├── AbstractDenseSemiringVector.java │ │ │ ├── SemiringTensorMixin.java │ │ │ └── TensorOverSemiring.java │ │ └── smart_visitors │ │ │ ├── AddVisitor.java │ │ │ ├── DivVisitor.java │ │ │ ├── ElemMultVisitor.java │ │ │ ├── MatMultVisitor.java │ │ │ ├── MatrixVisitor.java │ │ │ └── SubVisitor.java │ ├── dense │ │ ├── CMatrix.java │ │ ├── CTensor.java │ │ ├── CVector.java │ │ ├── FieldMatrix.java │ │ ├── FieldTensor.java │ │ ├── FieldVector.java │ │ ├── Matrix.java │ │ ├── RingMatrix.java │ │ ├── RingTensor.java │ │ ├── RingVector.java │ │ ├── SemiringMatrix.java │ │ ├── SemiringTensor.java │ │ ├── SemiringVector.java │ │ ├── Tensor.java │ │ ├── Vector.java │ │ └── package-info.java │ ├── package-info.java │ └── sparse │ │ ├── CooCMatrix.java │ │ ├── CooCTensor.java │ │ ├── CooCVector.java │ │ ├── CooFieldMatrix.java │ │ ├── CooFieldTensor.java │ │ ├── CooFieldVector.java │ │ ├── CooMatrix.java │ │ ├── CooRingMatrix.java │ │ ├── CooRingTensor.java │ │ ├── CooRingVector.java │ │ ├── CooSemiringMatrix.java │ │ ├── CooSemiringTensor.java │ │ ├── CooSemiringVector.java │ │ ├── CooTensor.java │ │ ├── CooVector.java │ │ ├── CsrCMatrix.java │ │ ├── CsrFieldMatrix.java │ │ ├── CsrMatrix.java │ │ ├── CsrRingMatrix.java │ │ ├── CsrSemiringMatrix.java │ │ ├── PermutationMatrix.java │ │ ├── SparseValidation.java │ │ ├── SymmTriDiag.java │ │ └── package-info.java │ ├── concurrency │ ├── Configurations.java │ ├── TensorOperation.java │ ├── ThreadManager.java │ └── package-info.java │ ├── io │ ├── MatrixMarketHeader.java │ ├── MatrixMarketReader.java │ ├── MatrixMarketWriter.java │ ├── PrettyPrint.java │ ├── PrintOptions.java │ ├── TensorReader.java │ ├── TensorWriter.java │ ├── package-info.java │ └── parsing │ │ ├── ComplexNumberLexer.java │ │ ├── ComplexNumberParser.java │ │ ├── Lexer.java │ │ └── Token.java │ ├── linalg │ ├── Condition.java │ ├── DirectSum.java │ ├── Eigen.java │ ├── Invert.java │ ├── MatrixNorms.java │ ├── PositiveDefiniteness.java │ ├── RowEchelon.java │ ├── SubSpace.java │ ├── TensorInvert.java │ ├── VectorNorms.java │ ├── decompositions │ │ ├── Decomposition.java │ │ ├── balance │ │ │ ├── Balancer.java │ │ │ ├── ComplexBalancer.java │ │ │ ├── RealBalancer.java │ │ │ └── package-info.java │ │ ├── chol │ │ │ ├── Cholesky.java │ │ │ ├── ComplexCholesky.java │ │ │ ├── RealCholesky.java │ │ │ └── package-info.java │ │ ├── hess │ │ │ ├── ComplexHess.java │ │ │ ├── HermHess.java │ │ │ ├── RealHess.java │ │ │ ├── SymmHess.java │ │ │ └── package-info.java │ │ ├── lu │ │ │ ├── ComplexLU.java │ │ │ ├── FieldLU.java │ │ │ ├── LU.java │ │ │ ├── RealLU.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── qr │ │ │ ├── ComplexQR.java │ │ │ ├── RealQR.java │ │ │ └── package-info.java │ │ ├── schur │ │ │ ├── ComplexSchur.java │ │ │ ├── RealSchur.java │ │ │ ├── Schur.java │ │ │ └── package-info.java │ │ ├── svd │ │ │ ├── ComplexSVD.java │ │ │ ├── RealSVD.java │ │ │ ├── SVD.java │ │ │ └── package-info.java │ │ └── unitary │ │ │ ├── ComplexUnitaryDecomposition.java │ │ │ ├── RealUnitaryDecomposition.java │ │ │ ├── UnitaryDecomposition.java │ │ │ └── package-info.java │ ├── ops │ │ ├── MatrixMultiplyDispatcher.java │ │ ├── RealDenseMatrixMultiplyDispatcher.java │ │ ├── RealDenseTensorBinaryOperation.java │ │ ├── TensorDot.java │ │ ├── TransposeDispatcher.java │ │ ├── common │ │ │ ├── complex │ │ │ │ ├── Complex128Ops.java │ │ │ │ ├── Complex64Ops.java │ │ │ │ └── package-info.java │ │ │ ├── field_ops │ │ │ │ ├── FieldOps.java │ │ │ │ └── package-info.java │ │ │ ├── real │ │ │ │ ├── AggregateReal.java │ │ │ │ ├── RealOps.java │ │ │ │ ├── RealProperties.java │ │ │ │ └── package-info.java │ │ │ ├── ring_ops │ │ │ │ ├── CompareRing.java │ │ │ │ ├── RingOps.java │ │ │ │ ├── RingProperties.java │ │ │ │ └── package-info.java │ │ │ └── semiring_ops │ │ │ │ ├── AggregateSemiring.java │ │ │ │ ├── CompareSemiring.java │ │ │ │ ├── SemiringOps.java │ │ │ │ ├── SemiringProperties.java │ │ │ │ ├── TransformSemiRing.java │ │ │ │ └── package-info.java │ │ ├── dense │ │ │ ├── DenseConcat.java │ │ │ ├── DenseEquals.java │ │ │ ├── DenseOps.java │ │ │ ├── DenseTranspose.java │ │ │ ├── complex │ │ │ │ ├── ComplexDenseDeterminant.java │ │ │ │ └── package-info.java │ │ │ ├── field_ops │ │ │ │ ├── DenseFieldDeterminant.java │ │ │ │ ├── DenseFieldElemDiv.java │ │ │ │ ├── DenseFieldOps.java │ │ │ │ ├── DenseFieldVectorOps.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── real │ │ │ │ ├── AggregateDenseReal.java │ │ │ │ ├── RealDenseDeterminant.java │ │ │ │ ├── RealDenseElemDiv.java │ │ │ │ ├── RealDenseElemMult.java │ │ │ │ ├── RealDenseEquals.java │ │ │ │ ├── RealDenseMatMult.java │ │ │ │ ├── RealDenseMatMultTranspose.java │ │ │ │ ├── RealDenseOps.java │ │ │ │ ├── RealDenseProperties.java │ │ │ │ ├── RealDenseSetOps.java │ │ │ │ ├── RealDenseTensorDot.java │ │ │ │ ├── RealDenseTranspose.java │ │ │ │ ├── RealDenseVectorOps.java │ │ │ │ └── package-info.java │ │ │ ├── real_field_ops │ │ │ │ ├── RealFieldDenseElemDiv.java │ │ │ │ ├── RealFieldDenseElemMult.java │ │ │ │ ├── RealFieldDenseEquals.java │ │ │ │ ├── RealFieldDenseMatMult.java │ │ │ │ ├── RealFieldDenseMatMultTranspose.java │ │ │ │ ├── RealFieldDenseOps.java │ │ │ │ ├── RealFieldDenseVectorOps.java │ │ │ │ └── package-info.java │ │ │ ├── ring_ops │ │ │ │ ├── DenseRingHermitianTranspose.java │ │ │ │ ├── DenseRingTensorOps.java │ │ │ │ ├── DenseRingVectorNorms.java │ │ │ │ ├── DenseRingVectorOps.java │ │ │ │ └── package-info.java │ │ │ └── semiring_ops │ │ │ │ ├── DenseSemiringConversions.java │ │ │ │ ├── DenseSemiringElemMult.java │ │ │ │ ├── DenseSemiringMatMult.java │ │ │ │ ├── DenseSemiringMatMultDispatcher.java │ │ │ │ ├── DenseSemiringMatMultTranspose.java │ │ │ │ ├── DenseSemiringOps.java │ │ │ │ ├── DenseSemiringTensorDot.java │ │ │ │ ├── DenseSemiringVectorOps.java │ │ │ │ └── package-info.java │ │ ├── dense_sparse │ │ │ ├── coo │ │ │ │ ├── field_ops │ │ │ │ │ ├── DenseCooFieldEquals.java │ │ │ │ │ ├── DenseCooFieldMatMult.java │ │ │ │ │ ├── DenseCooFieldMatrixOps.java │ │ │ │ │ ├── DenseCooFieldTensorOps.java │ │ │ │ │ └── DenseCooFieldVectorOps.java │ │ │ │ ├── real │ │ │ │ │ ├── RealDenseCooTensorOps.java │ │ │ │ │ ├── RealDenseSparseEquals.java │ │ │ │ │ ├── RealDenseSparseMatMult.java │ │ │ │ │ ├── RealDenseSparseMatrixMultTranspose.java │ │ │ │ │ ├── RealDenseSparseMatrixOps.java │ │ │ │ │ └── RealDenseSparseVectorOps.java │ │ │ │ ├── real_complex │ │ │ │ │ ├── RealComplexDenseCooMatOps.java │ │ │ │ │ ├── RealComplexDenseCooOps.java │ │ │ │ │ ├── RealComplexDenseSparseEquals.java │ │ │ │ │ └── RealComplexDenseSparseVectorOps.java │ │ │ │ └── real_field_ops │ │ │ │ │ ├── RealFieldDenseCooMatMult.java │ │ │ │ │ ├── RealFieldDenseCooMatMultTranspose.java │ │ │ │ │ ├── RealFieldDenseCooMatrixOps.java │ │ │ │ │ ├── RealFieldDenseCooOps.java │ │ │ │ │ └── RealFieldDenseCooVectorOps.java │ │ │ └── csr │ │ │ │ ├── field_ops │ │ │ │ └── DenseCsrFieldOps.java │ │ │ │ ├── real │ │ │ │ ├── RealCsrDenseMatMult.java │ │ │ │ └── RealCsrDenseOps.java │ │ │ │ ├── real_complex │ │ │ │ └── RealComplexCsrDenseOps.java │ │ │ │ ├── real_field_ops │ │ │ │ ├── RealFieldDenseCsrMatMult.java │ │ │ │ └── RealFieldDenseCsrOps.java │ │ │ │ └── semiring_ops │ │ │ │ └── DenseCsrSemiringMatMult.java │ │ ├── dispatch │ │ │ ├── BiTensorOpDispatcher.java │ │ │ ├── Cm128DeMatMultDispatcher.java │ │ │ ├── Cm128DeMatMultKernels.java │ │ │ ├── Cm128DeMatVecMultDispatcher.java │ │ │ ├── LRUCache.java │ │ │ ├── ReDeMatMultDispatcher.java │ │ │ ├── ReDeMatMultKernels.java │ │ │ ├── ReDeMatVecMultDispatcher.java │ │ │ └── configs │ │ │ │ ├── Cm128DeMatMultDispatchConfigs.java │ │ │ │ └── ReDeMatMultDispatchConfigs.java │ │ ├── package-info.java │ │ └── sparse │ │ │ ├── SparseElementSearch.java │ │ │ ├── SparseUtils.java │ │ │ ├── coo │ │ │ ├── CooConcat.java │ │ │ ├── CooConversions.java │ │ │ ├── CooDataSorter.java │ │ │ ├── CooGetSet.java │ │ │ ├── CooManipulations.java │ │ │ ├── CooProperties.java │ │ │ ├── CooTensorDot.java │ │ │ ├── CooTranspose.java │ │ │ ├── package-info.java │ │ │ ├── real │ │ │ │ ├── RealCooMatrixGetSet.java │ │ │ │ ├── RealCooTensorDot.java │ │ │ │ ├── RealCooTensorOps.java │ │ │ │ ├── RealCooVectorOps.java │ │ │ │ ├── RealSparseEquals.java │ │ │ │ ├── RealSparseManipulations.java │ │ │ │ ├── RealSparseMatMult.java │ │ │ │ ├── RealSparseMatrixManipulations.java │ │ │ │ ├── RealSparseMatrixOps.java │ │ │ │ ├── RealSparseMatrixProperties.java │ │ │ │ ├── RealSparseNorms.java │ │ │ │ └── package-info.java │ │ │ ├── real_complex │ │ │ │ ├── RealComplexCooConcats.java │ │ │ │ ├── RealComplexCooTensorOps.java │ │ │ │ ├── RealComplexSparseEquals.java │ │ │ │ ├── RealComplexSparseMatOps.java │ │ │ │ ├── RealComplexSparseMatrixMultiplication.java │ │ │ │ ├── RealComplexSparseVectorOps.java │ │ │ │ └── package-info.java │ │ │ ├── ring_ops │ │ │ │ ├── CooRingHermTranspose.java │ │ │ │ ├── CooRingMatrixOps.java │ │ │ │ ├── CooRingNorms.java │ │ │ │ ├── CooRingTensorOps.java │ │ │ │ ├── CooRingVectorOps.java │ │ │ │ └── package-info.java │ │ │ └── semiring_ops │ │ │ │ ├── CooSemiringEquals.java │ │ │ │ ├── CooSemiringMatMult.java │ │ │ │ ├── CooSemiringMatrixOps.java │ │ │ │ ├── CooSemiringMatrixProperties.java │ │ │ │ ├── CooSemiringTensorOps.java │ │ │ │ ├── CooSemiringVectorOps.java │ │ │ │ └── package-info.java │ │ │ └── csr │ │ │ ├── CsrConversions.java │ │ │ ├── CsrOps.java │ │ │ ├── CsrProperties.java │ │ │ ├── real │ │ │ ├── RealCsrEquals.java │ │ │ ├── RealCsrManipulations.java │ │ │ ├── RealCsrMatMult.java │ │ │ ├── RealCsrMatrixTensorDot.java │ │ │ ├── RealCsrOps.java │ │ │ └── RealCsrProperties.java │ │ │ ├── real_complex │ │ │ ├── RealComplexCsrMatMult.java │ │ │ └── RealComplexCsrOps.java │ │ │ ├── ring_ops │ │ │ └── CsrRingProperties.java │ │ │ └── semiring_ops │ │ │ ├── SemiringCsrMatMult.java │ │ │ ├── SemiringCsrOps.java │ │ │ └── SemiringCsrProperties.java │ ├── package-info.java │ ├── solvers │ │ ├── LinearMatrixSolver.java │ │ ├── LinearSolver.java │ │ ├── exact │ │ │ ├── ComplexExactSolver.java │ │ │ ├── ComplexExactTensorSolver.java │ │ │ ├── ExactSolver.java │ │ │ ├── ExactTensorSolver.java │ │ │ ├── RealExactSolver.java │ │ │ ├── RealExactTensorSolver.java │ │ │ ├── package-info.java │ │ │ └── triangular │ │ │ │ ├── BackSolver.java │ │ │ │ ├── ComplexBackSolver.java │ │ │ │ ├── ComplexForwardSolver.java │ │ │ │ ├── ForwardSolver.java │ │ │ │ ├── RealBackSolver.java │ │ │ │ ├── RealForwardSolver.java │ │ │ │ └── package-info.java │ │ ├── lstsq │ │ │ ├── ComplexLstsqSolver.java │ │ │ ├── LstsqSolver.java │ │ │ ├── RealLstsqSolver.java │ │ │ └── package-info.java │ │ └── package-info.java │ └── transformations │ │ ├── Givens.java │ │ ├── Householder.java │ │ ├── Projection.java │ │ ├── Rotation.java │ │ ├── View.java │ │ └── package-info.java │ ├── numbers │ ├── BoolSemiring.java │ ├── Complex128.java │ ├── Complex64.java │ ├── Field.java │ ├── RealFloat32.java │ ├── RealFloat64.java │ ├── RealInt16.java │ ├── RealInt32.java │ ├── Ring.java │ ├── Semiring.java │ └── package-info.java │ ├── rng │ ├── RandomArray.java │ ├── RandomComplex.java │ ├── RandomDenseTensor.java │ ├── RandomSparseTensor.java │ ├── RandomState.java │ ├── distributions │ │ ├── Complex128BiGaussian.java │ │ ├── Complex128UniformDisk.java │ │ ├── Complex128UniformRect.java │ │ ├── Distribution.java │ │ ├── RealGaussian.java │ │ ├── RealUniform.java │ │ └── package-info.java │ └── package-info.java │ └── util │ ├── ArrayBuilder.java │ ├── ArrayConversions.java │ ├── ArrayJoiner.java │ ├── ArrayUtils.java │ ├── ErrorMessages.java │ ├── Flag4jConstants.java │ ├── StringUtils.java │ ├── ValidateParameters.java │ ├── exceptions │ ├── Flag4jParsingException.java │ ├── LinearAlgebraException.java │ ├── SingularMatrixException.java │ ├── TensorShapeException.java │ └── package-info.java │ └── package-info.java └── test ├── data └── matrix_market │ ├── array │ ├── CmDe3x3.mtx │ ├── CmDe5x2.mtx │ ├── CmDeHerm5x5.mtx │ ├── ReDe2x4.mtx │ ├── ReDe3x2.mtx │ ├── ReDe3x3.mtx │ ├── ReDe3x3_out.mtx │ ├── ReDe49x15.mtx │ ├── ReDe5x2_out.mtx │ ├── ReDe7x14_out.mtx │ └── ReDeSymm5x5.mtx │ └── coordinate │ ├── ReCoo5x5_8.mtx │ ├── ReCoo5x5_8_out.mtx │ ├── can___24.mtx │ ├── can___24_out.mtx │ ├── fidapm05.mtx │ ├── fidapm05_out.mtx │ ├── jgl009.mtx │ └── jgl009_out.mtx └── java └── org └── flag4j ├── CustomAssertions.java ├── TestHelpers.java ├── TestUtils.java ├── arrays ├── ShapeTests.java ├── dense │ ├── complex_matrix │ │ ├── CMatrixAddTests.java │ │ ├── CMatrixConstructorTests.java │ │ ├── CMatrixConversionTests.java │ │ ├── CMatrixCsrMatMultTests.java │ │ ├── CMatrixDirectSumTests.java │ │ ├── CMatrixElemDivTests.java │ │ ├── CMatrixElemMultTests.java │ │ ├── CMatrixEqualsTests.java │ │ ├── CMatrixInversionTests.java │ │ ├── CMatrixMatVecMultTests.java │ │ ├── CMatrixMultTests.java │ │ ├── CMatrixNormTests.java │ │ ├── CMatrixPropertiesTests.java │ │ ├── CMatrixRemoveRowColTests.java │ │ ├── CMatrixReshapeTests.java │ │ ├── CMatrixRoundTests.java │ │ ├── CMatrixScaleOpsTests.java │ │ ├── CMatrixSetOperationTests.java │ │ ├── CMatrixStackTests.java │ │ ├── CMatrixSubTests.java │ │ ├── CMatrixToStringTests.java │ │ ├── CMatrixUnaryOpsTests.java │ │ └── CMatrixZeroOnesTests.java │ ├── complex_tensor │ │ ├── CTensorAddTests.java │ │ ├── CTensorConstructorTests.java │ │ ├── CTensorConversionTests.java │ │ ├── CTensorDotTests.java │ │ ├── CTensorElemDivTests.java │ │ ├── CTensorElemMultTests.java │ │ ├── CTensorReshapeTests.java │ │ ├── CTensorSubTests.java │ │ ├── CTensorToStringTests.java │ │ ├── CTensorTransposeTest.java │ │ └── CTensorTransposeTests.java │ ├── complex_vector │ │ ├── CVectorAddTests.java │ │ ├── CVectorAggregateTests.java │ │ ├── CVectorConstructorTests.java │ │ ├── CVectorCrossTests.java │ │ ├── CVectorElemDivTests.java │ │ ├── CVectorElemMultTests.java │ │ ├── CVectorElemOppTests.java │ │ ├── CVectorEqualsTests.java │ │ ├── CVectorInnerProductTests.java │ │ ├── CVectorNormTests.java │ │ ├── CVectorOuterProductTests.java │ │ ├── CVectorRepeatTests.java │ │ ├── CVectorScalMultDivTests.java │ │ ├── CVectorSetTests.java │ │ ├── CVectorStackJoinExtendTest.java │ │ ├── CVectorSubTests.java │ │ └── CVectorZeroOneTests.java │ ├── matrix │ │ ├── MatrixAddSubEqTests.java │ │ ├── MatrixAddTests.java │ │ ├── MatrixAggregationTests.java │ │ ├── MatrixConstructorTests.java │ │ ├── MatrixConversionTests.java │ │ ├── MatrixCsrCMatMultTests.java │ │ ├── MatrixDetTests.java │ │ ├── MatrixDirectSumTests.java │ │ ├── MatrixElemDivTests.java │ │ ├── MatrixElemMultTests.java │ │ ├── MatrixElemOppTests.java │ │ ├── MatrixElementScalarTests.java │ │ ├── MatrixFibTests.java │ │ ├── MatrixGetTests.java │ │ ├── MatrixInversionTests.java │ │ ├── MatrixMultTests.java │ │ ├── MatrixPropertiesTests.java │ │ ├── MatrixRemoveRowColTests.java │ │ ├── MatrixReshapeTests.java │ │ ├── MatrixScalMultTests.java │ │ ├── MatrixSetOperationTests.java │ │ ├── MatrixStackTests.java │ │ ├── MatrixSubTests.java │ │ ├── MatrixToStringTest.java │ │ ├── MatrixTransposeTests.java │ │ ├── MatrixTriangularTests.java │ │ ├── MatrixVectorCheckTests.java │ │ ├── MatrixVectorTests.java │ │ ├── MatrixZerosOnesTests.java │ │ └── NormTests.java │ ├── semiring_matrix │ │ └── SemiringToStringTests.java │ ├── tensor │ │ ├── TensorAddTests.java │ │ ├── TensorAggregateTests.java │ │ ├── TensorConstructorTests.java │ │ ├── TensorConversionTests.java │ │ ├── TensorDotTests.java │ │ ├── TensorElemDivTests.java │ │ ├── TensorElemMultTests.java │ │ ├── TensorEqualsTests.java │ │ ├── TensorGetSetTests.java │ │ ├── TensorPropertiesTests.java │ │ ├── TensorReshapeTests.java │ │ ├── TensorScalMultDivTests.java │ │ ├── TensorSubTests.java │ │ ├── TensorToStringTests.java │ │ ├── TensorTransposeTests.java │ │ └── TensorUnitaryOperationTests.java │ └── vector │ │ ├── VectorAddSubEqTests.java │ │ ├── VectorAddSubTests.java │ │ ├── VectorAggregateTests.java │ │ ├── VectorConstructorTests.java │ │ ├── VectorConversionTests.java │ │ ├── VectorCopyTransposeTests.java │ │ ├── VectorCrossProductTests.java │ │ ├── VectorElemMultDivTests.java │ │ ├── VectorElementwiseTests.java │ │ ├── VectorEqualsTests.java │ │ ├── VectorInnerProductTest.java │ │ ├── VectorNormTest.java │ │ ├── VectorOuterProductTests.java │ │ ├── VectorPerpParallelTests.java │ │ ├── VectorRepeatTests.java │ │ ├── VectorScaleMultDivTests.java │ │ ├── VectorSetTests.java │ │ ├── VectorShapeTests.java │ │ ├── VectorStackJoinTests.java │ │ ├── VectorToStringTest.java │ │ └── VectorZeroOnesTests.java └── sparse │ ├── complex_coo_matrix │ ├── CooCMatrixAddSubTests.java │ ├── CooCMatrixAugmentTests.java │ ├── CooCMatrixAugmentVectorTests.java │ ├── CooCMatrixDirectSumTests.java │ ├── CooCMatrixElemDivTests.java │ ├── CooCMatrixElemMultTests.java │ ├── CooCMatrixGetRowColTests.java │ ├── CooCMatrixGetSliceTests.java │ ├── CooCMatrixIsCloseToITests.java │ ├── CooCMatrixIsSymmTests.java │ ├── CooCMatrixMultTransposeTests.java │ ├── CooCMatrixNormTests.java │ ├── CooCMatrixSetColTests.java │ ├── CooCMatrixSetTests.java │ ├── CooCMatrixStackTests.java │ └── CooCMatrixToStringTests.java │ ├── complex_csr_matrix │ ├── ComplexCsrDenseMatMultTests.java │ ├── ComplexCsrMatMultTests.java │ ├── ComplexRealCsrCsrMatMultTests.java │ ├── CsrCMatrixAddSubTests.java │ ├── CsrCMatrixEqualsTests.java │ ├── CsrCMatrixGetRowColTests.java │ ├── CsrCMatrixGetSetTests.java │ ├── CsrCMatrixGetSliceTests.java │ ├── CsrCMatrixIsSymmTests.java │ ├── CsrCMatrixNormTests.java │ ├── CsrCMatrixRowColSwapTests.java │ ├── CsrCMatrixToDenseTests.java │ ├── CsrCMatrixToStringTests.java │ ├── CsrCMatrixToVectorTests.java │ ├── CsrCMatrixTransposeTests.java │ └── CsrCMatrixTriDiagTests.java │ ├── coo_matrix │ ├── CooMatrixAddSubTests.java │ ├── CooMatrixAugmentTests.java │ ├── CooMatrixAugmentVectorTests.java │ ├── CooMatrixConstructorTests.java │ ├── CooMatrixDirectSumTests.java │ ├── CooMatrixElemDivTests.java │ ├── CooMatrixElemMultTests.java │ ├── CooMatrixEqualsTest.java │ ├── CooMatrixGetRowColTests.java │ ├── CooMatrixGetSliceTests.java │ ├── CooMatrixGetTests.java │ ├── CooMatrixIsSymmTests.java │ ├── CooMatrixMatMultTests.java │ ├── CooMatrixMultTransposeTests.java │ ├── CooMatrixSetRowColTests.java │ ├── CooMatrixSetSliceTests.java │ ├── CooMatrixSetTests.java │ ├── CooMatrixStackTests.java │ ├── CooMatrixToStringTests.java │ └── IsIdentityTests.java │ ├── csr_matrix │ ├── CsrElemMultTests.java │ ├── CsrMatrixAddSubTests.java │ ├── CsrMatrixGetRowColTests.java │ ├── CsrMatrixGetSetTests.java │ ├── CsrMatrixGetSliceTest.java │ ├── CsrMatrixNormTests.java │ ├── CsrMatrixRowColSwapTests.java │ ├── CsrMatrixToDenseTests.java │ ├── CsrMatrixToStringTests.java │ ├── CsrMatrixToVectorTests.java │ ├── CsrMatrixTransposeTests.java │ ├── CsrMatrixTriDiagTests.java │ ├── RealComplexCsrCsrMatMultTests.java │ ├── RealComplexCsrDenseMatMultTests.java │ ├── RealCsrCsrMatMultTests.java │ ├── RealCsrDenseMatMultTests.java │ └── RealCsrEqualsTests.java │ ├── sparse_complex_tensor │ ├── ComplexSparseTensorElemBinOpsTests.java │ ├── CooCTensorConstructorTests.java │ ├── CooCTensorGetSetTests.java │ ├── CooCTensorHermTransposeTests.java │ ├── CooCTensorReshapeTests.java │ └── CooCTensorToStringTests.java │ ├── sparse_complex_vector │ ├── CooCVectorAddTests.java │ ├── CooCVectorConstructorTests.java │ ├── CooCVectorConversionTests.java │ ├── CooCVectorElemDivTests.java │ ├── CooCVectorElemMultTests.java │ ├── CooCVectorJoinTests.java │ ├── CooCVectorRepeatTests.java │ ├── CooCVectorReshapeTests.java │ ├── CooCVectorSubTests.java │ └── CooCVectorUnaryOpTests.java │ ├── sparse_tensor │ ├── CooTensorConstructorTests.java │ ├── CooTensorGetSetTests.java │ ├── CooTensorReshapeTests.java │ ├── CooTensorSpElemBinOpsTests.java │ ├── CooTensorToStringTests.java │ ├── CooTensorTransposeTests.java │ └── RealComplexCooTensorBinOpsTests.java │ └── sparse_vector │ ├── CooVectorAddTests.java │ ├── CooVectorAggregateTests.java │ ├── CooVectorConstructorTests.java │ ├── CooVectorConversionTests.java │ ├── CooVectorElemDivTests.java │ ├── CooVectorElemMultTests.java │ ├── CooVectorInnerProdTests.java │ ├── CooVectorJoinTests.java │ ├── CooVectorOuterProductTest.java │ ├── CooVectorRepeatTests.java │ ├── CooVectorReshapeTests.java │ ├── CooVectorSetTests.java │ ├── CooVectorSubTests.java │ ├── CooVectorToStringTests.java │ ├── CooVectorUnaryOpTests.java │ └── SparseVectorCooSortTest.java ├── complex_coo_matrix ├── CooCMatrixConstructorTests.java ├── CooCMatrixRemoveRowColTests.java ├── CooCMatrixReshapeTests.java └── CooCMatrixSwapRowColTests.java ├── complex_numbers ├── Complex128BinaryOpsTest.java ├── Complex128ComparisonTest.java ├── Complex128ConstructorTest.java ├── Complex128ConversionTest.java ├── Complex128ExponentialTest.java ├── Complex128GettersSettersTest.java ├── Complex128MinMaxSumTest.java ├── Complex128PropertiesTest.java ├── Complex128RoundTest.java ├── Complex128SqrtTest.java ├── Complex128ToStringTest.java ├── Complex128TrigTest.java └── Complex128UnaryOpsTest.java ├── io ├── MatrixMarketMatrices.java ├── MatrixMarketReadTests.java ├── MatrixMarketWriteTests.java └── PrintOptionsTests.java ├── linalg ├── CMatrixInvertTests.java ├── ComplexEigenTests.java ├── MatrixInvertTests.java ├── RealEigenTests.java ├── SubSpaceTests.java ├── decompositions │ ├── ComplexCholeskyTests.java │ ├── ComplexHessenburgTests.java │ ├── ComplexLUTests.java │ ├── ComplexQRTests.java │ ├── RealBalanceTest.java │ ├── RealCholeskyTests.java │ ├── RealHessenburgTests.java │ ├── RealLUTests.java │ ├── RealQRTests.java │ ├── RealSVDTests.java │ ├── RealSchurTests.java │ └── RealSymmHessTests.java ├── ops │ ├── RealDenseMatrixMultiplyDispatcherTests.java │ ├── common │ │ └── real │ │ │ ├── MatrixNormTests.java │ │ │ └── unaryOperationTests.java │ ├── dense │ │ ├── complex │ │ │ ├── CMatrixMultiplyTests.java │ │ │ ├── ComplexDenseDetTests.java │ │ │ ├── ComplexDenseMatMultTransposeTests.java │ │ │ ├── ComplexDenseOpsTests.java │ │ │ └── ComplexDenseTransposeTests.java │ │ ├── real │ │ │ ├── MatrixMultiplyTests.java │ │ │ ├── RealDenseMatMultTransposeTests.java │ │ │ ├── RealDenseOpsTests.java │ │ │ ├── RealDenseSetOpsTests.java │ │ │ ├── RealDenseTransposeTests.java │ │ │ └── RoundTests.java │ │ └── real_complex │ │ │ ├── RealComplexDenseMatMultTests.java │ │ │ ├── RealComplexDenseMatMultTransposeTests.java │ │ │ └── RealComplexDenseOpsTests.java │ ├── dense_sparse │ │ ├── complex │ │ │ └── ComplexDenseCooMatrixMultiplicationTests.java │ │ ├── real │ │ │ ├── RealDenseSparseMatMultTests.java │ │ │ └── RealDenseSparseMatMultTransposeTests.java │ │ └── real_complex │ │ │ ├── RealComplexDenseSparseMatMultTests.java │ │ │ └── RealComplexDenseSparseMatMultTransposeTests.java │ └── sparse │ │ └── coo │ │ ├── complex │ │ └── ComplexSparseMatMultTests.java │ │ └── real │ │ ├── RealSpareMatrixAddTests.java │ │ └── RealSparseMatMultTests.java ├── solvers │ ├── ComplexExactSolverTests.java │ ├── ComplexForwardSolverTests.java │ ├── RealExactSolverTests.java │ ├── RealForwardSolverTest.java │ └── RealLstsqSolverTests.java └── transformations │ ├── GivensTests.java │ ├── ProjectionTests.java │ └── RotationTests.java ├── numbers ├── bool_semirings │ ├── ConstructorConstantsTests.java │ └── OpsTests.java ├── fields │ ├── Complex64BinaryOpsTest.java │ ├── Complex64ComparisonTest.java │ ├── Complex64ConstructorTest.java │ ├── Complex64ConversionTest.java │ ├── Complex64ExponentialTest.java │ ├── Complex64GettersSettersTest.java │ ├── Complex64MinMaxSumTest.java │ ├── Complex64PropertiesTest.java │ ├── Complex64RoundTest.java │ ├── Complex64SqrtTest.java │ ├── Complex64ToStringTest.java │ ├── Complex64TrigTest.java │ └── Complex64UnaryOpsTest.java └── rings │ └── RealIntTests.java └── util ├── ArrayUtilTests.java ├── ErrorMessagesTests.java ├── StringUtilsTests.java └── ValidateParametersTests.java /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: SonarCloud 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | types: [opened, synchronize, reopened] 8 | jobs: 9 | build: 10 | name: Build and analyze 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | with: 15 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 16 | - name: Set up JDK 23 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: 23 20 | distribution: 'zulu' # Alternative distribution options are available. 21 | - name: Cache SonarCloud packages 22 | uses: actions/cache@v3 23 | with: 24 | path: ~/.sonar/cache 25 | key: ${{ runner.os }}-sonar 26 | restore-keys: ${{ runner.os }}-sonar 27 | - name: Cache Maven packages 28 | uses: actions/cache@v3 29 | with: 30 | path: ~/.m2 31 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 32 | restore-keys: ${{ runner.os }}-m2 33 | - name: Build and analyze 34 | env: 35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any 36 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 37 | run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=jacobdwatters_Flag4j 38 | -------------------------------------------------------------------------------- /.github/workflows/javadoc-gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy Javadoc 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | jobs: 8 | # 1) Build the Javadoc and upload as artifact 9 | build-docs: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@v4.2.2 14 | 15 | # 1.1) Setup Java 16 | - name: Set up JDK 23 17 | uses: actions/setup-java@v4.7.0 18 | with: 19 | distribution: 'zulu' 20 | java-version: 23 21 | 22 | # 1.2) Setup python 23 | - name: Set up Python 24 | uses: actions/setup-python@v5.4.0 25 | with: 26 | python-version: '3.x' 27 | 28 | # 1.3) Build Javadoc 29 | - name: Build Javadoc 30 | run: | 31 | mvn clean install -DskipTests 32 | mvn javadoc:javadoc \ 33 | -Dmaven.javadoc.failOnError=false \ 34 | -Dmaven.javadoc.skip=false 35 | 36 | # 1.5) Find and convert all specified HTML equations to LaTeX equations and inject MathJax script 37 | - name: Convert LaTeX 38 | run: python scripts/convert_latex.py 39 | 40 | # 1.6) Upload generated docs as artifact 41 | - name: Upload Pages Artifact 42 | uses: actions/upload-pages-artifact@v3.0.1 43 | with: 44 | path: target/reports/apidocs 45 | 46 | # --- 2) Deploy the artifact to GitHub Pages 47 | deploy-docs: 48 | needs: build-docs 49 | runs-on: ubuntu-latest 50 | permissions: 51 | pages: write # required 52 | id-token: write # required 53 | steps: 54 | - name: Deploy to GitHub Pages 55 | uses: actions/deploy-pages@v4.0.5 56 | with: 57 | token: ${{ secrets.GITHUB_TOKEN }} 58 | -------------------------------------------------------------------------------- /.github/workflows/maven-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a package using Maven and then publish it to GitHub packages when a release is created 2 | # For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path 3 | 4 | name: Maven Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | permissions: 15 | contents: read 16 | packages: write 17 | 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Set up JDK 23 21 | uses: actions/setup-java@v3 22 | with: 23 | java-version: '23' 24 | distribution: 'temurin' 25 | server-id: github # Value of the distributionManagement/repository/id field of the pom.xml 26 | settings-path: ${{ github.workspace }} # location for the settings.xml file 27 | 28 | - name: Build with Maven 29 | run: mvn -B package --file pom.xml 30 | 31 | - name: Publish to GitHub Packages Apache Maven 32 | run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml 33 | env: 34 | GITHUB_TOKEN: ${{ github.token }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ Stuff 2 | /.idea/ 3 | /flag4j.iml 4 | qodana.yaml 5 | 6 | # Build files and docs 7 | /target/ 8 | /docs/ 9 | /local_scripts/ 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Jacob Watters 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /configs/CmDeMatMult.properties: -------------------------------------------------------------------------------- 1 | # These configurations are used to dynamically select the kernel to use when computing a complex dense matrix product. 2 | # It is STRONGLY discouraged to edit these values by hand. 3 | 4 | # The number of matrix shape pairs to cache to the kernel to use does not need to be recomputed. 5 | cacheSize = 64 6 | 7 | # If the total number of elements in both matrices summed is less than this value, the standard kernel will be used. 8 | # This is regardless of the "squareness". This will trump all the following configs. 9 | smallThreshold = 2450 10 | 11 | # For two matrices of shapes (M, N) and (N, K), if max(M, N, K) / min(M, N, K) < aspectThreshold then 12 | # the logic for "near square" matrices will be used to choose the kernel. 13 | aspectThreshold = 2.0 14 | 15 | # For "square enough" matrices, if N is less than this value, a concurrent implementation of the standard kernel will be used. 16 | squareMtStandardThreshold = 50 17 | 18 | # For "square enough" matrices, if N is less than this value, a concurrent kernel leveraging reordered loops will be used. 19 | # If N is larger than this value, a concurrent kernel leveraging reordered loops and blocking will be used. 20 | squareMtReorderedThreshold = 2048 21 | 22 | # For matrices not "square enough", a threshold used to determine if a sequential or concurrent kernel should be used 23 | # bases in the size of the smallest dimensions between the two matrices. 24 | minDimSmallThreshold = 10 25 | 26 | # For matrices not "square enough", a threshold used to determine if a which concurrent kernel should be used 27 | # based on the size of the maximum dimensions between the two matrices. 28 | wideMtReorderedThreshold = 25 29 | -------------------------------------------------------------------------------- /configs/GeneralConfigs.properties: -------------------------------------------------------------------------------- 1 | # The block/tile size to used in blocked/tiled algorithms. 2 | blockSize = 64 3 | 4 | # The level of parallelism to use in concurrent algorithms. Set this value to zero to set this to the 5 | # number of available processors at runtime. 6 | # - If zero or negative, the parallelism level will be set to: availableProcessors + parallelism. 7 | parallelism = 0 -------------------------------------------------------------------------------- /configs/ReDeMatMult.properties: -------------------------------------------------------------------------------- 1 | # These configurations are used to dynamically select the kernel to use when computing a real dense matrix product. 2 | # It is STRONGLY discouraged to edit these values by hand. 3 | 4 | # The number of matrix shape pairs to cache to the kernel to use does not need to be recomputed. 5 | cacheSize = 64 6 | 7 | # If the total number of elements in both matrices summed is less than this value, the standard kernel will be used. 8 | # This is regardless of the "squareness". This will trump all the following configs. 9 | smallThreshold = 2450 10 | 11 | # For two matrices of shapes (M, N) and (N, K), if max(M, N, K) / min(M, N, K) < aspectThreshold then 12 | # the logic for "near square" matrices will be used to choose the kernel. 13 | aspectThreshold = 2.0 14 | 15 | # For "square enough" matrices, if N is less than this value, a concurrent implementation of the standard kernel will be used. 16 | squareMtStandardThreshold = 50 17 | 18 | # For "square enough" matrices, if N is less than this value, a concurrent kernel leveraging reordered loops will be used. 19 | # If N is larger than this value, a concurrent kernel leveraging reordered loops and blocking will be used. 20 | squareMtReorderedThreshold = 2048 21 | 22 | # For matrices not "square enough", a threshold used to determine if a sequential or concurrent kernel should be used 23 | # bases in the size of the smallest dimensions between the two matrices. 24 | minDimSmallThreshold = 10 25 | 26 | # For matrices not "square enough", a threshold used to determine if a which concurrent kernel should be used 27 | # based on the size of the maximum dimensions between the two matrices. 28 | wideMtReorderedThreshold = 25 29 | 30 | # When the second matrix is a column vector and the first matrix is "square enough", if N is less than this value, a 31 | # sequential matrix-vector product kernel will be used. Otherwise, a concurrent kernel will be used. 32 | squareStandardVecThreshold = 256 33 | -------------------------------------------------------------------------------- /figures/intelij_doc_render.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flag4j/Flag4j/3a7d4eca4c02d61fec625988210ec20c2ad09c24/figures/intelij_doc_render.png -------------------------------------------------------------------------------- /figures/latex_in_javadoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flag4j/Flag4j/3a7d4eca4c02d61fec625988210ec20c2ad09c24/figures/latex_in_javadoc.png -------------------------------------------------------------------------------- /qodana.yaml: -------------------------------------------------------------------------------- 1 | #-------------------------------------------------------------------------------# 2 | # Qodana analysis is configured by qodana.yaml file # 3 | # https://www.jetbrains.com/help/qodana/qodana-yaml.html # 4 | #-------------------------------------------------------------------------------# 5 | version: "1.0" 6 | 7 | #Specify inspection profile for code analysis 8 | profile: 9 | name: qodana.starter 10 | 11 | #Enable inspections 12 | #include: 13 | # - name: 14 | 15 | #Disable inspections 16 | #exclude: 17 | # - name: 18 | # paths: 19 | # - 20 | 21 | projectJDK: 23 #(Applied in CI/CD pipeline) 22 | 23 | #Execute shell command before Qodana execution (Applied in CI/CD pipeline) 24 | #bootstrap: sh ./prepare-qodana.sh 25 | 26 | #Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) 27 | #plugins: 28 | # - id: #(plugin id can be found at https://plugins.jetbrains.com) 29 | 30 | #Specify Qodana linter for analysis (Applied in CI/CD pipeline) 31 | linter: jetbrains/qodana-jvm:latest 32 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/IntTuple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.arrays; 26 | 27 | import java.util.Arrays; 28 | import java.util.StringJoiner; 29 | 30 | /** 31 | *

Data record to store an ordered list of integers (i.e., an n-tuple). 32 | *

IntTuples are immutable. 33 | * 34 | * @param data The values of the integer tuple. 35 | * @see Tuple 36 | * @see Pair 37 | * @see Triple 38 | */ 39 | public record IntTuple(int[] data) { 40 | 41 | /** 42 | * Gets the size of the tuple. 43 | * @return The size of this tuple. 44 | */ 45 | public int size() { 46 | return data.length; 47 | } 48 | 49 | 50 | @Override 51 | public int hashCode() { 52 | return Arrays.hashCode(data); 53 | } 54 | 55 | 56 | @Override 57 | public boolean equals(Object obj) { 58 | if(obj == null) return false; 59 | if(obj.getClass() != getClass()) return false; 60 | 61 | return Arrays.equals(data, ((IntTuple)obj).data); 62 | } 63 | 64 | 65 | @Override 66 | public String toString() { 67 | StringJoiner joiner = new StringJoiner(", ", "(", ")"); 68 | 69 | for(int d : data) 70 | joiner.add(String.valueOf(d)); 71 | 72 | return "Tuple[data=" + joiner.toString() + "]"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.arrays; 26 | 27 | /** 28 | *

Data record to store a pair of values (i.e., a 2-tuple). 29 | *

Pairs are immutable. 30 | * 31 | * @param The type of the first element in the pair. 32 | * @param The type of the second element in the pair. 33 | * @see Tuple 34 | * @see Triple 35 | */ 36 | public record Pair(T first, V second) { 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/SparseMatrixData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.arrays; 26 | 27 | import org.flag4j.util.ArrayConversions; 28 | 29 | import java.util.List; 30 | 31 | 32 | /** 33 | *

Data class for storing information for a sparse (CSR or COO) matrix. 34 | *

This record stores three lists: the non-zero data, the row indices/pointers, and the column indices. 35 | * @param shape Shape of the matrix. 36 | * @param data Non-zero data of the sparse matrix. 37 | * @param rowData Non-zero row indices/pointers. 38 | * @param colData Non-zero column indices. 39 | * @param Type of the data of the matrix. 40 | */ 41 | public record SparseMatrixData(Shape shape, List data, List rowData, List colData) { 42 | 43 | 44 | /** 45 | * Converts the row indices of this sparse matrix data to a primitive integer array. 46 | * @return A primitive integer array containing the row indices of this sparse matrix data. 47 | */ 48 | public int[] rowIndicesToArray() { 49 | return ArrayConversions.fromIntegerList(rowData); 50 | } 51 | 52 | 53 | /** 54 | * Converts the column indices of this sparse matrix data to a primitive integer array. 55 | * @return A primitive integer array containing the column indices of this sparse matrix data. 56 | */ 57 | public int[] colIndicesToArray() { 58 | return ArrayConversions.fromIntegerList(colData); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/SparseTensorData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.arrays; 26 | 27 | import java.util.List; 28 | 29 | /** 30 | *

Data class for storing information for a sparse COO tensor. 31 | *

This record stores two arrays: the non-zero data, the non-zero indices. 32 | * @param shape Shape of the tensor. 33 | * @param data Non-zero data of the sparse tensor. 34 | * @param indices Non-zero indices of the sparse tensor. 35 | * @param Type of the data of the tensor. 36 | */ 37 | public record SparseTensorData(Shape shape, List data, List indices) { 38 | 39 | /** 40 | * Converts the indices of this sparse tensor data to a 2D primitive integer array. 41 | * @return A 2D primitive integer array containing the indices of this sparse tensor data. 42 | */ 43 | public int[][] indicesToArray() { 44 | return indices.toArray(new int[indices.size()][]); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/SparseVectorData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.arrays; 26 | 27 | import org.flag4j.util.ArrayConversions; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | *

Data class for storing information for a sparse COO vector. 33 | *

This record stores two lists: the non-zero data and the indices of the vector. 34 | * 35 | * @param shape Shape of the vector. 36 | * @param data Non-zero data of the sparse COO vector. 37 | * @param indices Non-zero indices of the sparse COO vector. 38 | */ 39 | public record SparseVectorData(Shape shape, List data, List indices) { 40 | 41 | 42 | /** 43 | * Converts the indices of this sparse vector data to a primitive integer array. 44 | * @return A primitive integer array containing the indices of this sparse vector data. 45 | */ 46 | public int[] indicesToArray() { 47 | return ArrayConversions.fromIntegerList(indices); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/Triple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.arrays; 26 | 27 | /** 28 | *

Data record to store a triplet of values (i.e., a 3-tuple). 29 | *

Triples are immutable. 30 | * 31 | * @param The type of the elements in the triple. 32 | * @see Tuple 33 | * @see Pair 34 | */ 35 | public record Triple(T first, T second, T third) { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/Tuple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.arrays; 26 | 27 | import java.util.Arrays; 28 | import java.util.StringJoiner; 29 | 30 | /** 31 | *

Data record to store an ordered list of values (i.e., an n-tuple). 32 | *

Tuples are immutable. 33 | * @param data The values of the tuple. 34 | * @param The type of the elements in the tuple. 35 | * @see IntTuple 36 | * @see Pair 37 | * @see Triple 38 | */ 39 | public record Tuple(T... data) { 40 | 41 | /** 42 | * Gets the size of the tuple. 43 | * @return The size of this tuple. 44 | */ 45 | public int size() { 46 | return data.length; 47 | } 48 | 49 | 50 | @Override 51 | public int hashCode() { 52 | return Arrays.hashCode(data); 53 | } 54 | 55 | 56 | @Override 57 | public boolean equals(Object obj) { 58 | if(obj == null) return false; 59 | if(obj.getClass() != getClass()) return false; 60 | 61 | return Arrays.equals(data, ((Tuple)obj).data); 62 | } 63 | 64 | 65 | @Override 66 | public String toString() { 67 | StringJoiner joiner = new StringJoiner(", ", "(", ")"); 68 | 69 | for(T d : data) 70 | joiner.add(d.toString()); 71 | 72 | return "Tuple[data=" + joiner.toString() + "]"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/arrays/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of "smart" array objects, the tensor shape object, and tuples. 27 | */ 28 | package org.flag4j.arrays; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/concurrency/TensorOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.concurrency; 26 | 27 | 28 | /** 29 | * Functional interface for general tensor operation over a specified index range. 30 | */ 31 | @FunctionalInterface 32 | public interface TensorOperation { 33 | 34 | /** 35 | * Applies a tensor operation over the specified index range. 36 | * @param startIdx Staring index for operation (inclusive). 37 | * @param endIdx Ending index for operation (exclusive). 38 | */ 39 | void apply(int startIdx, int endIdx); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/concurrency/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Utilities, configurations, and management for multithreaded implementations. 27 | */ 28 | package org.flag4j.concurrency; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/io/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * IO for vector, matrix, and tensor objects. 27 | */ 28 | package org.flag4j.io; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/balance/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of matrix balancing for real and complex matrices. 27 | */ 28 | package org.flag4j.linalg.decompositions.balance; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/chol/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of the Cholesky decomposition for real and complex matrices. 27 | */ 28 | package org.flag4j.linalg.decompositions.chol; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/hess/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of the Hessenberg decomposition for real and complex matrices. 27 | */ 28 | package org.flag4j.linalg.decompositions.hess; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/lu/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of the LU decomposition for real, complex, and field matrices. 27 | */ 28 | package org.flag4j.linalg.decompositions.lu; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Contains base abstract class for all matrix decompositions. 27 | */ 28 | package org.flag4j.linalg.decompositions; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/qr/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of the QR decomposition for real and complex matrices. 27 | */ 28 | package org.flag4j.linalg.decompositions.qr; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/schur/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of the Schur decomposition for real and complex matrices. 27 | */ 28 | package org.flag4j.linalg.decompositions.schur; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/svd/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides implementations of the singular value decomposition for real and complex matrices. 27 | */ 28 | package org.flag4j.linalg.decompositions.svd; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/decompositions/unitary/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Provides abstract classes useful for implementing real or complex matrix decompositions which proceed by unitary transformations. 27 | */ 28 | package org.flag4j.linalg.decompositions.unitary; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/RealDenseTensorBinaryOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2023-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.linalg.ops; 26 | 27 | 28 | import org.flag4j.arrays.Shape; 29 | 30 | /** 31 | * Functional interface for creating a lambda which implements an operation acting on two real dense tensors. 32 | */ 33 | @FunctionalInterface 34 | public interface RealDenseTensorBinaryOperation { 35 | 36 | 37 | /** 38 | * Applies the specified binary operation on the two tensors. 39 | * @param src1 Entries of the first tensor. 40 | * @param shape1 Shape of the first tensor. 41 | * @param src2 Entries of the second tensor. 42 | * @param shape2 Shape of the second tensor. 43 | * @return The result of applying the specified binary operation to the two tensors. 44 | */ 45 | double[] apply(double[] src1, Shape shape1, double[] src2, Shape shape2); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/common/complex/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on two complex array objects. Operations are agnostic to sparsity/density. 27 | */ 28 | package org.flag4j.linalg.ops.common.complex; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/common/field_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on two {@link org.flag4j.numbers.Field Field} array objects. Operations are agnostic to 27 | * sparsity/density. 28 | */ 29 | package org.flag4j.linalg.ops.common.field_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/common/real/AggregateReal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.linalg.ops.common.real; 26 | 27 | 28 | /** 29 | * This utility class contains several low-level methods useful for computing aggregation ops on dense/sparse tensors. 30 | */ 31 | public final class AggregateReal { 32 | 33 | private AggregateReal() { 34 | // Hide default constructor. 35 | 36 | } 37 | 38 | 39 | /** 40 | * Computes the sum of all data in this tensor. This can be applied to either real dense or spase tensors. 41 | * @param entries Entries of the tensor. 42 | * @return The sum of all data in this tensor. 43 | */ 44 | public static double sum(double... entries) { 45 | double sum = 0; 46 | for(double value : entries) 47 | sum += value; 48 | 49 | return sum; 50 | } 51 | 52 | 53 | /** 54 | * Computes the sum of all data in this tensor. This can be applied to either real dense or spase tensors. 55 | * @param entries Entries of the tensor. 56 | * @return The sum of all data in this tensor. 57 | */ 58 | public static double prod(double... entries) { 59 | double sum = 0; 60 | for(double value : entries) 61 | sum *= value; 62 | 63 | return sum; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/common/real/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on two real array objects. 27 | * Operations are agnostic to sparsity/density. 28 | */ 29 | package org.flag4j.linalg.ops.common.real; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/common/ring_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on two {@link org.flag4j.numbers.Ring Ring} array objects. 27 | * Operations are agnostic to sparsity/density. 28 | */ 29 | package org.flag4j.linalg.ops.common.ring_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/common/semiring_ops/SemiringProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.linalg.ops.common.semiring_ops; 26 | 27 | import org.flag4j.numbers.Semiring; 28 | 29 | 30 | /** 31 | * This utility class provides methods useful for determining properties of semiring tensors. 32 | */ 33 | public final class SemiringProperties { 34 | 35 | private SemiringProperties() { 36 | // Hide default constructor in utility class. 37 | } 38 | 39 | /** 40 | * Checks if an array contains only zeros. 41 | * @param src Array to check if it only contains zeros. 42 | * @return True if the {@code src} array contains only zeros; {@code false} otherwise. 43 | */ 44 | public static > boolean isZeros(T[] src) { 45 | for(T value: src) 46 | if(!value.isZero()) return false; 47 | 48 | return true; 49 | } 50 | 51 | 52 | /** 53 | * Checks if an array contains only ones. 54 | * @param src Array to check if it only contains ones. 55 | * @return {@code true} if the {@code src} array contains only ones; {@code false} otherwise. 56 | */ 57 | public static > boolean isOnes(T[] src) { 58 | for(T value: src) 59 | if(!value.isOne()) return false; 60 | 61 | return true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/common/semiring_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on two {@link org.flag4j.numbers.Semiring Semiring} array objects. 27 | * Operations are agnostic to sparsity/density. 28 | */ 29 | package org.flag4j.linalg.ops.common.semiring_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/DenseEquals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.linalg.ops.dense; 26 | 27 | import org.flag4j.arrays.Shape; 28 | 29 | import java.util.Arrays; 30 | 31 | 32 | /** 33 | * This class provides methods for checking the equality of dense tensors. 34 | */ 35 | public final class DenseEquals { 36 | 37 | private DenseEquals() { 38 | // Hide constructor for utility class. for utility class. 39 | } 40 | 41 | 42 | /** 43 | * Checks if two dense tensors are equal. For the purposes of this method, {@link Double#NaN} values are considered equal. 44 | * @param src1 Entries of first tensor. 45 | * @param shape1 Shape of first tensor. 46 | * @param src2 Entries of second tensor. 47 | * @param shape2 Shape of second tensor. 48 | * @return True if the two tensors are the same shape and numerically element-wise equivalent. 49 | */ 50 | public static boolean tensorEquals(T[] src1, Shape shape1, T[] src2, Shape shape2) { 51 | return shape1.equals(shape2) && Arrays.equals(src1, src2); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/complex/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on complex dense array objects. 27 | */ 28 | package org.flag4j.linalg.ops.dense.complex; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/field_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on {@link org.flag4j.numbers.Field Field} dense array objects. 27 | */ 28 | package org.flag4j.linalg.ops.dense.field_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on generic dense array objects. 27 | */ 28 | package org.flag4j.linalg.ops.dense; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/real/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on real dense array objects. 27 | */ 28 | package org.flag4j.linalg.ops.dense.real; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/real_field_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations between real array objects and {@link org.flag4j.numbers.Field Field} dense array 27 | * objects. 28 | */ 29 | package org.flag4j.linalg.ops.dense.real_field_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/ring_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on {@link org.flag4j.numbers.Ring Ring} dense array objects. 27 | */ 28 | package org.flag4j.linalg.ops.dense.ring_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dense/semiring_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on {@link org.flag4j.numbers.Semiring Semiring} dense array objects. 27 | */ 28 | package org.flag4j.linalg.ops.dense.semiring_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/dispatch/LRUCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.linalg.ops.dispatch; 26 | 27 | import java.util.LinkedHashMap; 28 | import java.util.Map; 29 | 30 | /** 31 | * A least recently used (LRU) cache. 32 | * @param Type of the key in the cache. 33 | * @param Type of the value in the cache. 34 | */ 35 | public class LRUCache extends LinkedHashMap { 36 | 37 | /** 38 | * Capacity of the LRU cache. 39 | */ 40 | private final int capacity; // maximum number of entries allowed 41 | 42 | 43 | /** 44 | * Creates an LRU cache with the specified capacity. If this capacity is exceeded the lest-recently accessed entry will be 45 | * removed. 46 | * @param capacity Maximum number of entries the LRUCache can store. 47 | */ 48 | public LRUCache(int capacity) { 49 | super(capacity, 0.75f, true); 50 | this.capacity = capacity; 51 | } 52 | 53 | 54 | @Override 55 | protected boolean removeEldestEntry(Map.Entry eldest) { 56 | return size() > capacity; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * General linear algebra operations. 27 | */ 28 | package org.flag4j.linalg.ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/sparse/coo/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on generic sparse COO (coordinate) array objects. 27 | */ 28 | package org.flag4j.linalg.ops.sparse.coo; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/sparse/coo/real/RealSparseManipulations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2023-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.linalg.ops.sparse.coo.real; 26 | 27 | 28 | /** 29 | * This utility class provides methods for inserting/removing values in a real sparse vector. 30 | */ 31 | public final class RealSparseManipulations { 32 | 33 | private RealSparseManipulations() { 34 | // Hide default constructor in utility class. 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/sparse/coo/real/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on real sparse COO (coordinate) array objects. 27 | */ 28 | package org.flag4j.linalg.ops.sparse.coo.real; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/sparse/coo/real_complex/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations between real and complex sparse COO (coordinate) array objects. 27 | */ 28 | package org.flag4j.linalg.ops.sparse.coo.real_complex; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/sparse/coo/ring_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on {@link org.flag4j.numbers.Ring Ring} sparse COO (coordinate) array objects. 27 | */ 28 | package org.flag4j.linalg.ops.sparse.coo.ring_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/ops/sparse/coo/semiring_ops/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Implementations of operations on {@link org.flag4j.numbers.Semiring Semiring} sparse COO (coordinate) array objects. 27 | */ 28 | package org.flag4j.linalg.ops.sparse.coo.semiring_ops; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * General purpose linear algebra operations including condition number evaluations, eigenvalue/eigenvector computations, matrix 27 | * inversion, and subspace analysis. 28 | */ 29 | package org.flag4j.linalg; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/solvers/exact/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Contains solvers which solve well determined linear tensor and matrix equations in an exact sense. 27 | */ 28 | package org.flag4j.linalg.solvers.exact; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/solvers/exact/triangular/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Contains solvers which solve well determined triangular linear matrix equations in an exact sense. 27 | */ 28 | package org.flag4j.linalg.solvers.exact.triangular; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/solvers/lstsq/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Solvers for under-, well-, or over-determined linear systems in a least-squares sense. 27 | */ 28 | package org.flag4j.linalg.solvers.lstsq; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/solvers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Contains base abstract classes for all linear matrix and tensor equation solvers. 27 | */ 28 | package org.flag4j.linalg.solvers; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/linalg/transformations/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | *

Utility classes for computing and applying matrix and vector transformations. 27 | */ 28 | package org.flag4j.linalg.transformations; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/numbers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | *

Provides algebraic structures such as semirings, rings, and fields, 27 | * along with their concrete implementations. 28 | * 29 | *

This module defines interfaces representing algebraic structures: 30 | *

    31 | *
  • {@link Semiring}
  • 32 | *
  • {@link Ring}
  • 33 | *
  • {@link Field}
  • 34 | *
35 | * and provides concrete implementations for various data types: 36 | *
    37 | *
  • {@link org.flag4j.numbers.BoolSemiring}
  • 38 | *
  • {@link org.flag4j.numbers.RealInt16}
  • 39 | *
  • {@link org.flag4j.numbers.RealInt32}
  • 40 | *
  • {@link org.flag4j.numbers.RealFloat32}
  • 41 | *
  • {@link org.flag4j.numbers.RealFloat64}
  • 42 | *
  • {@link org.flag4j.numbers.Complex64}
  • 43 | *
  • {@link org.flag4j.numbers.Complex128}
  • 44 | *
45 | * 46 | *

These abstractions allow for generic programming with mathematical structures, 47 | * enabling algorithms to work over any data type that adheres to the specified algebraic structure. 48 | */ 49 | package org.flag4j.numbers; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/rng/distributions/Distribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.rng.distributions; 26 | 27 | 28 | import java.util.Random; 29 | 30 | 31 | /** 32 | * Base class for all statistical distributions. 33 | * @param The type of the output of the distributions probability density function. 34 | */ 35 | public abstract class Distribution { 36 | 37 | /** 38 | * The random number generator to use when sampling this distribution. 39 | */ 40 | protected final U rng; 41 | 42 | /** 43 | * Constructs a distribution with a random number generator to be used for sampling this distribution. 44 | * @param rng Random number generator to use when sampling this distribution. 45 | */ 46 | protected Distribution(U rng) { 47 | this.rng = rng; 48 | } 49 | 50 | 51 | /** 52 | * Randomly samples this distribution. 53 | * @return A random value distributed according to this distribution. 54 | */ 55 | public abstract T sample(); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/rng/distributions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Statistical distributions useful for repeated random sampling. 27 | */ 28 | package org.flag4j.rng.distributions; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/rng/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Pseudo-random generation of real/complex numbers, and arrays, vectors, matrices, and tensors. 27 | */ 28 | package org.flag4j.rng; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/util/exceptions/Flag4jParsingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.util.exceptions; 26 | 27 | /** 28 | * An exception which is thrown when an unexpected error occurs while trying to parse a string 29 | * representing some algebraic structure (e.g. matrix, complex number, etc.). 30 | */ 31 | public class Flag4jParsingException extends RuntimeException { 32 | 33 | /** 34 | * Creates a {@link Flag4jParsingException} to be thrown when an unexpected error occurs while trying to parse a string 35 | * representing some algebraic structure (e.g. matrix, complex number, etc.). 36 | * @param errMsg Error message for the exception. 37 | */ 38 | public Flag4jParsingException(String errMsg) { 39 | super(errMsg); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/util/exceptions/LinearAlgebraException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.util.exceptions; 26 | 27 | 28 | /** 29 | * An exception which is thrown when a linear algebra related error occurs at runtime. 30 | */ 31 | public class LinearAlgebraException extends RuntimeException { 32 | 33 | /** 34 | * Creates a {@link LinearAlgebraException} to be thrown for a linear algebra related error. 35 | * @param errMsg Error message for the exception. 36 | */ 37 | public LinearAlgebraException(String errMsg) { 38 | super(errMsg); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/util/exceptions/SingularMatrixException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.util.exceptions; 26 | 27 | /** 28 | * An exception which is thrown when some operation not defined for singular matrices is attempted to be 29 | * performed on a singular matrix. For example, attempting to invert a singular matrix. 30 | */ 31 | public class SingularMatrixException extends LinearAlgebraException { 32 | 33 | private static final String INFO = "Matrix is singular."; 34 | 35 | /** 36 | * Creates a SingularMatrixException with the simple error message "Matrix is singular." 37 | */ 38 | public SingularMatrixException() { 39 | super(INFO); 40 | } 41 | 42 | /** 43 | * Creates a SingularMatrixException with a specified error message. Note, the string " Matrix is singular." will 44 | * be automatically appended to the error message. 45 | * @param errMsg Error message to display when this SingularMatrixException is thrown. 46 | */ 47 | public SingularMatrixException(String errMsg) { 48 | super(errMsg + " " + INFO); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/util/exceptions/TensorShapeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2024-2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package org.flag4j.util.exceptions; 26 | 27 | /** 28 | * An exception to be thrown when there is an error related to tensor shapes. 29 | */ 30 | public class TensorShapeException extends LinearAlgebraException { 31 | 32 | /** 33 | * Creates a {@link TensorShapeException} to be thrown for a linear algebra related error. 34 | * 35 | * @param errMsg Error message for the exception. 36 | */ 37 | public TensorShapeException(String errMsg) { 38 | super(errMsg); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/flag4j/util/exceptions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Custom linear algebra and parsing related exceptions. 27 | */ 28 | package org.flag4j.util.exceptions; -------------------------------------------------------------------------------- /src/main/java/org/flag4j/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2025. Jacob Watters 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * General utilities for arrays, strings, data validation, and generating error messages. 27 | */ 28 | package org.flag4j.util; -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/CmDe3x3.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array complex general 2 | % 3 | 3 3 4 | 9.0808878356600644e+01 -1.6893672078977701e+01 5 | 9.4850075885931943e+01 8.0723188543691720e+01 6 | -4.3044797490419228e+01 5.1303897734408963e+01 7 | -9.1933204914100557e+01 -9.1730574664869152e+01 8 | 3.7823015726649032e+01 -6.9872144215007921e+01 9 | -4.4074890881174667e+01 8.2363304166632361e+01 10 | -8.4902569481465790e+01 -3.5093438239795347e+00 11 | -8.8936186138467463e+01 2.1595886501062722e+01 12 | -2.7633779239363278e+01 8.3038934151317932e+01 13 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/CmDe5x2.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array complex general 2 | % 3 | 5 2 4 | -9.9011354276924067e+01 5.3542842841538061e+01 5 | 3.7227873683117764e+01 -5.3771175784267996e+01 6 | -1.2072478586583060e+00 5.9191447575727466e+01 7 | 1.1075529177742055e+01 5.7867910096861124e+01 8 | -6.9946316433140368e+01 -1.7766835457413904e+01 9 | -6.5605086418918660e+01 -9.5051213709463255e+01 10 | 7.9327123845387831e+01 -2.1960773736477307e+01 11 | -3.2966497263372659e+01 -5.4547182420086401e+01 12 | -3.0066738625120720e+01 -2.7598345098490796e+01 13 | -8.1304272213940095e+01 7.4688229566273151e+01 14 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/CmDeHerm5x5.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array complex hermitian 2 | % 3 | % 4 | 5 5 5 | 5 2 6 | -1.3 0.14 7 | 4.1 23 8 | 1.234 0 9 | 0 900.2 10 | 24 14.5 11 | 50.123 -67 12 | 80.24 123 13 | 6 0 14 | -72.15 14.656 15 | 6.1 23 16 | -3 3 17 | 50.24 0.3 18 | 8 154 19 | -24.5 1 -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/ReDe2x4.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array real general 2 | 3 | 2 4 4 | 5 | 0.001415 6 | 23.425 7 | 122.5 8 | -0.0141 9 | 2.25 10 | 9023.4 11 | 3.41 12 | 13 | 14 | 15 | 16 | -0.00015 -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/ReDe3x2.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array real general 2 | 3 2 3 | 1 4 | 3 5 | 5 6 | 2 7 | 4 8 | 6 9 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/ReDe3x3.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array real general 2 | % matrix for testing I/O in Flag4j library. 3 | % This is a comment for testing purposes 4 | % ------------------------------------------ 5 | 3 3 6 | 1 7 | 8 | -2 9 | 3.0 10 | 4.0001 11 | 5.1e-4 12 | 6.0e5 13 | 14 | 15 | 14.1 16 | 3.15 17 | 1.923 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/ReDe3x3_out.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array real general 2 | % 3 | % 4 | 3 3 5 | 1.0 6 | 4.014E-9 7 | 1.4E57 8 | 2.0 9 | 11512.234 10 | -31.32 11 | 3.0 12 | 9.14E-4 13 | -7.8E-5 14 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/ReDe5x2_out.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array real general 2 | % 3 | % generated by Flag4j 4 | % test comment 5 | % 6 | 5 2 7 | 42.88975397315653 8 | 77.77634809247053 9 | -28.896793915896055 10 | 2.4693564393389664 11 | 94.83243949848998 12 | -7.229462112800718 13 | -72.67239859214298 14 | 58.541359482462894 15 | 66.05800124106074 16 | -25.279053739157845 17 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/ReDe7x14_out.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array real general 2 | % 3 | % 4 | 7 14 5 | -7.447708816878972 6 | -86.21557987388877 7 | 49.03904351423435 8 | -46.47398884676595 9 | -29.15855869563711 10 | 43.76237863765289 11 | 38.930486250578724 12 | 66.49760248549055 13 | -71.4641313232438 14 | -86.33785802772367 15 | 42.71015403568981 16 | 0.6195550397762588 17 | -13.365730589377776 18 | -40.75289725874711 19 | -72.78622988809545 20 | -92.95580839246931 21 | -15.805899967134792 22 | -11.128825519269341 23 | -47.05827490293024 24 | 82.7804044267719 25 | 54.23704681848716 26 | 41.6235915295199 27 | -0.3680447478712665 28 | 75.36935485411448 29 | -29.330713269456865 30 | 25.232040385677763 31 | 56.92302799125429 32 | -18.297334314575636 33 | -31.403389317838545 34 | -97.50930761134322 35 | 9.130269125962002 36 | 63.46470586331483 37 | 72.12780013594312 38 | -21.43440226221219 39 | -80.23103566382545 40 | -40.887147695530416 41 | 83.2789175937055 42 | -20.124697340853487 43 | -51.7979348652456 44 | -1.7140198889623122 45 | 24.191485579580103 46 | -15.91415205256908 47 | -67.0474509122703 48 | -42.989851445938186 49 | -72.26885624364974 50 | -65.51659087042822 51 | -86.62250138315524 52 | 70.28914492993198 53 | -89.96836670580623 54 | -90.8582545953998 55 | -76.59661024648996 56 | 13.09494188351779 57 | -95.22820507720454 58 | -42.68306230328673 59 | 32.52871773840192 60 | -56.57547635676507 61 | -59.95781767061856 62 | -69.76534583842295 63 | -68.44519881812307 64 | -40.48694455393181 65 | -1.3061953213015443 66 | -37.85533046022198 67 | 57.570203890653715 68 | 31.374756851538848 69 | 65.69107858408114 70 | -30.478450017531628 71 | 19.075087332249737 72 | -23.319364477617427 73 | 43.110571849373144 74 | 87.3908251716388 75 | 45.93517429414919 76 | 49.59567825921417 77 | 92.06800046120281 78 | 79.903550772859 79 | 62.32644610164198 80 | 42.937881425224106 81 | -70.70079949360459 82 | -97.11924214391045 83 | -62.39713193214867 84 | 2.675864196433224 85 | -22.39050376201679 86 | -7.13647848547248 87 | 43.62166633527525 88 | -41.973445835293546 89 | 12.910841152880877 90 | 2.683250182348644 91 | -40.67825029136656 92 | -91.05300975473477 93 | -73.07440996183917 94 | -47.14035249643109 95 | 8.523287416654242 96 | -79.98960506527497 97 | 90.98196785174684 98 | -26.625720694197355 99 | -6.022438916613069 100 | 13.485255789617327 101 | 21.445940867297807 102 | 43.66457374723146 103 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/array/ReDeSymm5x5.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix array real symmetric 2 | % 3 | % 4 | 5 5 5 | 5 6 | -1.3 7 | 4.1 8 | 1.234 9 | 900.2 10 | 24 11 | 50.123 12 | 80.24 13 | 6 14 | -72.15 15 | 6.1 16 | -3 17 | 50.24 18 | 8 19 | -24.5 -------------------------------------------------------------------------------- /src/test/data/matrix_market/coordinate/ReCoo5x5_8.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate real general 2 | % 3 | % 4 | 5 5 8 5 | 1 1 1.000e+00 6 | 2 2 1.050e+01 7 | 3 3 1.500e-02 8 | 1 4 6.000e+00 9 | 4 2 2.505e+02 10 | 4 4 -2.800e+02 11 | 4 5 3.332e+01 12 | 5 5 1.200e+01 13 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/coordinate/ReCoo5x5_8_out.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate real general 2 | % 3 | % 4 | 5 5 8 5 | 1 1 1.0 6 | 1 4 6.0 7 | 2 2 10.5 8 | 3 3 0.015 9 | 4 2 250.5 10 | 4 4 -280.0 11 | 4 5 33.32 12 | 5 5 12.0 13 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/coordinate/can___24.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate pattern symmetric 2 | 24 24 92 3 | 1 1 4 | 6 1 5 | 7 1 6 | 13 1 7 | 14 1 8 | 18 1 9 | 19 1 10 | 20 1 11 | 22 1 12 | 2 2 13 | 9 2 14 | 10 2 15 | 14 2 16 | 15 2 17 | 18 2 18 | 3 3 19 | 7 3 20 | 12 3 21 | 21 3 22 | 22 3 23 | 23 3 24 | 4 4 25 | 8 4 26 | 11 4 27 | 16 4 28 | 19 4 29 | 20 4 30 | 5 5 31 | 8 5 32 | 10 5 33 | 15 5 34 | 16 5 35 | 17 5 36 | 6 6 37 | 7 6 38 | 13 6 39 | 14 6 40 | 18 6 41 | 7 7 42 | 12 7 43 | 13 7 44 | 20 7 45 | 22 7 46 | 24 7 47 | 8 8 48 | 10 8 49 | 15 8 50 | 16 8 51 | 17 8 52 | 18 8 53 | 19 8 54 | 9 9 55 | 10 9 56 | 15 9 57 | 10 10 58 | 14 10 59 | 15 10 60 | 18 10 61 | 19 10 62 | 11 11 63 | 19 11 64 | 20 11 65 | 21 11 66 | 22 11 67 | 12 12 68 | 13 12 69 | 22 12 70 | 24 12 71 | 13 13 72 | 24 13 73 | 14 14 74 | 18 14 75 | 15 15 76 | 16 16 77 | 17 16 78 | 19 16 79 | 17 17 80 | 18 18 81 | 19 18 82 | 20 18 83 | 19 19 84 | 20 19 85 | 20 20 86 | 21 20 87 | 22 20 88 | 21 21 89 | 22 21 90 | 23 21 91 | 22 22 92 | 23 22 93 | 23 23 94 | 24 24 95 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/coordinate/can___24_out.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate pattern symmetric 2 | % 3 | % Generated by Flag4j 4 | % 5 | 24 24 92 6 | 1 1 7 | 2 2 8 | 3 3 9 | 4 4 10 | 5 5 11 | 6 1 12 | 6 6 13 | 7 1 14 | 7 3 15 | 7 6 16 | 7 7 17 | 8 4 18 | 8 5 19 | 8 8 20 | 9 2 21 | 9 9 22 | 10 2 23 | 10 5 24 | 10 8 25 | 10 9 26 | 10 10 27 | 11 4 28 | 11 11 29 | 12 3 30 | 12 7 31 | 12 12 32 | 13 1 33 | 13 6 34 | 13 7 35 | 13 12 36 | 13 13 37 | 14 1 38 | 14 2 39 | 14 6 40 | 14 10 41 | 14 14 42 | 15 2 43 | 15 5 44 | 15 8 45 | 15 9 46 | 15 10 47 | 15 15 48 | 16 4 49 | 16 5 50 | 16 8 51 | 16 16 52 | 17 5 53 | 17 8 54 | 17 16 55 | 17 17 56 | 18 1 57 | 18 2 58 | 18 6 59 | 18 8 60 | 18 10 61 | 18 14 62 | 18 18 63 | 19 1 64 | 19 4 65 | 19 8 66 | 19 10 67 | 19 11 68 | 19 16 69 | 19 18 70 | 19 19 71 | 20 1 72 | 20 4 73 | 20 7 74 | 20 11 75 | 20 18 76 | 20 19 77 | 20 20 78 | 21 3 79 | 21 11 80 | 21 20 81 | 21 21 82 | 22 1 83 | 22 3 84 | 22 7 85 | 22 11 86 | 22 12 87 | 22 20 88 | 22 21 89 | 22 22 90 | 23 3 91 | 23 21 92 | 23 22 93 | 23 23 94 | 24 7 95 | 24 12 96 | 24 13 97 | 24 24 98 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/coordinate/jgl009.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate real general 2 | % matrix for testing I/O in Flag4j library. 3 | 4 | 9 12 50 5 | 1 1 1 6 | 2 1 2 7 | 4 1 4 8 | 5 1 15.2 9 | 6 1 -0.0024 10 | 7 1 102.4 11 | 8 1 89.24 12 | 9 1 1.414 13 | 2 2 14024 14 | 3 2 10.303 15 | 8 2 -99.2002 16 | 9 2 12 17 | 2 3 1E-3 18 | 3 3 2.4e15 19 | 4 3 351.3 20 | 5 3 0.000001 21 | 6 3 1.4 22 | 7 3 213 23 | 8 3 3 24 | 9 3 1 25 | 4 4 3.14 26 | 5 4 0.14 27 | 6 4 41 28 | 7 4 14 29 | 8 4 14 30 | 9 4 145.2 31 | 4 5 14.3 32 | 5 5 -42.1 33 | 6 5 -4.1e-9 34 | 7 5 3 35 | 8 5 13 36 | 9 5 133.4 37 | 4 6 1.45 38 | 5 6 3.51 39 | 6 6 0.00324 40 | 7 6 35.5 41 | 8 6 15.51 42 | 9 6 145.5 43 | 1 7 12.5 44 | 2 7 97151.2098451 45 | 3 7 3.141592653589793238 46 | 8 7 0.0 47 | 9 7 14.2 48 | 8 8 35 49 | 9 8 32 50 | 1 9 1.5 51 | 2 9 -1.0000 52 | 3 9 3 53 | 8 9 -5 54 | 9 12 16.1 55 | -------------------------------------------------------------------------------- /src/test/data/matrix_market/coordinate/jgl009_out.mtx: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate real general 2 | % 3 | % 4 | 9 12 50 5 | 1 1 1.0 6 | 1 7 12.5 7 | 1 9 1.5 8 | 2 1 2.0 9 | 2 2 14024.0 10 | 2 3 0.001 11 | 2 7 97151.2098451 12 | 2 9 -1.0 13 | 3 2 10.303 14 | 3 3 2.4E15 15 | 3 7 3.141592653589793 16 | 3 9 3.0 17 | 4 1 4.0 18 | 4 3 351.3 19 | 4 4 3.14 20 | 4 5 14.3 21 | 4 6 1.45 22 | 5 1 15.2 23 | 5 3 1.0E-6 24 | 5 4 0.14 25 | 5 5 -42.1 26 | 5 6 3.51 27 | 6 1 -0.0024 28 | 6 3 1.4 29 | 6 4 41.0 30 | 6 5 -4.1E-9 31 | 6 6 0.00324 32 | 7 1 102.4 33 | 7 3 213.0 34 | 7 4 14.0 35 | 7 5 3.0 36 | 7 6 35.5 37 | 8 1 89.24 38 | 8 2 -99.2002 39 | 8 3 3.0 40 | 8 4 14.0 41 | 8 5 13.0 42 | 8 6 15.51 43 | 8 7 0.0 44 | 8 8 35.0 45 | 8 9 -5.0 46 | 9 1 1.414 47 | 9 2 12.0 48 | 9 3 1.0 49 | 9 4 145.2 50 | 9 5 133.4 51 | 9 6 145.5 52 | 9 7 14.2 53 | 9 8 32.0 54 | 9 12 16.1 55 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/TestUtils.java: -------------------------------------------------------------------------------- 1 | package org.flag4j; 2 | 3 | import org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringMatrix; 4 | import org.flag4j.arrays.dense.Matrix; 5 | 6 | public final class TestUtils { 7 | 8 | private TestUtils() {} 9 | 10 | 11 | /** 12 | * @param a Matrix of interest. 13 | * @return {@code true} if the matrix only has zeros below the principle diagonal; {@code false} otherwise. 14 | */ 15 | public static boolean isUpperTriLike(Matrix a) { 16 | final int bound = Math.min(a.numRows, a.numCols); 17 | 18 | // Ensure lower half is zeros. 19 | for(int i=1; i a) { 35 | final int bound = Math.min(a.numRows, a.numCols); 36 | 37 | // Ensure lower half is zeros. 38 | for(int i=1; iA.fib(B)); 50 | 51 | 52 | // ------------------------- sub-case 3 ------------------------- 53 | aEntries = new double[][]{{1, -212}, 54 | {100.9, 80.1}, 55 | {12.3, 0}, 56 | {9, 6}}; 57 | A = new Matrix(aEntries); 58 | bEntries = new double[][]{{104, 0, 8.23}, 59 | {0.11135, -8, -3.123}, 60 | {-9.8, 109.4, 4}, 61 | {0, 0, 1}}; 62 | B = new Matrix(bEntries); 63 | 64 | assertThrows(LinearAlgebraException.class, ()->A.fib(B)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/matrix/MatrixInversionTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.matrix; 2 | 3 | import org.flag4j.arrays.dense.Matrix; 4 | import org.flag4j.linalg.Invert; 5 | import org.flag4j.util.exceptions.LinearAlgebraException; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.assertThrows; 10 | 11 | class MatrixInversionTests { 12 | 13 | double[][] aEntries, expEntries; 14 | Matrix A, exp; 15 | 16 | 17 | @Test 18 | void invTestCase() { 19 | // --------------------- sub-case 1 --------------------- 20 | aEntries = new double[][]{ 21 | {2, 55, 8}, 22 | {3, 1, 1}, 23 | {5, 4, 4} 24 | }; 25 | A = new Matrix(aEntries); 26 | expEntries = new double[][]{ 27 | {0.0, 0.5714285714285714, -0.14285714285714285}, 28 | {0.02127659574468085, 0.09726443768996962, -0.06686930091185411}, 29 | {-0.02127659574468085, -0.8115501519756839, 0.49544072948328266} 30 | }; 31 | exp = new Matrix(expEntries); 32 | 33 | assertEquals(exp, Invert.inv(A)); 34 | 35 | 36 | // --------------------- sub-case 2 --------------------- 37 | aEntries = new double[][]{ 38 | {1, 2}, 39 | {-2, -4} 40 | }; // This matrix is singular 41 | A = new Matrix(aEntries); 42 | 43 | assertThrows(RuntimeException.class, ()-> Invert.inv(A)); 44 | 45 | 46 | // --------------------- sub-case 3 --------------------- 47 | aEntries = new double[][]{ 48 | {2, 55, 8}, 49 | {3, 1, 1} 50 | }; 51 | A = new Matrix(aEntries); 52 | 53 | assertThrows(LinearAlgebraException.class, ()-> Invert.inv(A)); 54 | assertThrows(LinearAlgebraException.class, ()-> Invert.inv(A.T())); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/matrix/MatrixTransposeTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.matrix; 2 | 3 | import org.flag4j.arrays.dense.Matrix; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | class MatrixTransposeTests { 10 | Matrix A, expT, AT; 11 | double[][] aEntries, expEntries; 12 | 13 | 14 | @Test 15 | void transposeTestCase() { 16 | // --------------- sub-case 1 --------------- 17 | aEntries = new double[][]{ 18 | {1, 2, 3}, 19 | {4, 5, 6}}; 20 | expEntries = new double[][]{ 21 | {1, 4}, 22 | {2, 5}, 23 | {3, 6}}; 24 | A = new Matrix(aEntries); 25 | expT = new Matrix(expEntries); 26 | AT = A.T(); 27 | assertArrayEquals(expT.data, AT.data); 28 | assertEquals(expT.numRows(), AT.numRows()); 29 | assertEquals(expT.numCols(), AT.numCols()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/matrix/MatrixTriangularTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.matrix; 2 | 3 | import org.flag4j.arrays.dense.Matrix; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertFalse; 7 | import static org.junit.jupiter.api.Assertions.assertTrue; 8 | 9 | class MatrixTriangularTests { 10 | double[][] aEntries; 11 | Matrix A; 12 | 13 | @Test 14 | void triangularTestCase() { 15 | // ----------------- sub-case 1 ----------------- 16 | aEntries = new double[][]{{1, 3, 4}, {4, 5, 6}}; 17 | A = new Matrix(aEntries); 18 | assertFalse(A.isTri()); 19 | assertFalse(A.isTriL()); 20 | assertFalse(A.isTriU()); 21 | assertFalse(A.isDiag()); 22 | 23 | // ----------------- sub-case 2 ----------------- 24 | aEntries = new double[][]{ 25 | {1, 3, 4}, 26 | {4, 5, 6}, 27 | {9, 13.334, -8.123}}; 28 | A = new Matrix(aEntries); 29 | assertFalse(A.isTri()); 30 | assertFalse(A.isTriL()); 31 | assertFalse(A.isTriU()); 32 | assertFalse(A.isDiag()); 33 | 34 | // ----------------- sub-case 3 ----------------- 35 | aEntries = new double[][]{ 36 | {1, 0, 0}, 37 | {4, 5, 0}, 38 | {9, 13.334, -8.123}}; 39 | A = new Matrix(aEntries); 40 | assertTrue(A.isTri()); 41 | assertTrue(A.isTriL()); 42 | assertFalse(A.isTriU()); 43 | assertFalse(A.isDiag()); 44 | 45 | // ----------------- sub-case 4 ----------------- 46 | aEntries = new double[][]{ 47 | {1, 3, 4}, 48 | {0, 5, 6}, 49 | {0, 0, -8.123}}; 50 | A = new Matrix(aEntries); 51 | assertTrue(A.isTri()); 52 | assertFalse(A.isTriL()); 53 | assertTrue(A.isTriU()); 54 | assertFalse(A.isDiag()); 55 | 56 | // ----------------- sub-case 5 ----------------- 57 | aEntries = new double[][]{ 58 | {1, 0, 0}, 59 | {0, 5, 0}, 60 | {0, 0, -8.123}}; 61 | A = new Matrix(aEntries); 62 | assertTrue(A.isTri()); 63 | assertTrue(A.isTriL()); 64 | assertTrue(A.isTriU()); 65 | assertTrue(A.isDiag()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/matrix/MatrixVectorCheckTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.matrix; 2 | 3 | import org.flag4j.arrays.dense.Matrix; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class MatrixVectorCheckTests { 9 | double[][] aEntries; 10 | Matrix A; 11 | 12 | @Test 13 | void isVectorTestCase() { 14 | // ------------------ sub-case 1 ------------------ 15 | aEntries = new double[][]{{1.123, 5325.123}, {1.566, -2354.5767}}; 16 | A = new Matrix(aEntries); 17 | assertFalse(A.isVector()); 18 | 19 | // ------------------ sub-case 2 ------------------ 20 | aEntries = new double[][]{{1.123, 5325.123, 123.4}, {1.566, -2354.5767, 9}}; 21 | A = new Matrix(aEntries); 22 | assertFalse(A.isVector()); 23 | 24 | // ------------------ sub-case 3 ------------------ 25 | aEntries = new double[][]{{1.123, 5325.123, 123.4}}; 26 | A = new Matrix(aEntries); 27 | assertTrue(A.isVector()); 28 | 29 | // ------------------ sub-case 4 ------------------ 30 | aEntries = new double[][]{{1.123}}; 31 | A = new Matrix(aEntries); 32 | assertTrue(A.isVector()); 33 | 34 | // ------------------ sub-case 5 ------------------ 35 | aEntries = new double[][]{{1.123}, {-9234}, {-7234.23}, {0.3242}, {1}}; 36 | A = new Matrix(aEntries); 37 | assertTrue(A.isVector()); 38 | } 39 | 40 | @Test 41 | void vectorTypeTestCase() { 42 | // ------------------ sub-case 1 ------------------ 43 | aEntries = new double[][]{{1.123, 5325.123}, {1.566, -2354.5767}}; 44 | A = new Matrix(aEntries); 45 | assertEquals(-1, A.vectorType()); 46 | 47 | // ------------------ sub-case 2 ------------------ 48 | aEntries = new double[][]{{1.123, 5325.123, 123.4}, {1.566, -2354.5767, 9}}; 49 | A = new Matrix(aEntries); 50 | assertEquals(-1, A.vectorType()); 51 | 52 | // ------------------ sub-case 3 ------------------ 53 | aEntries = new double[][]{{1.123, 5325.123, 123.4}}; 54 | A = new Matrix(aEntries); 55 | assertEquals(1, A.vectorType()); 56 | 57 | // ------------------ sub-case 4 ------------------ 58 | aEntries = new double[][]{{1.123}}; 59 | A = new Matrix(aEntries); 60 | assertEquals(0, A.vectorType()); 61 | 62 | // ------------------ sub-case 5 ------------------ 63 | aEntries = new double[][]{{1.123}, {-9234}, {-7234.23}, {0.3242}, {1}}; 64 | A = new Matrix(aEntries); 65 | assertEquals(2, A.vectorType()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/matrix/MatrixZerosOnesTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.matrix; 2 | 3 | import org.flag4j.arrays.dense.Matrix; 4 | import org.flag4j.util.ArrayBuilder; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class MatrixZerosOnesTests { 9 | 10 | double[][] aEntries; 11 | Matrix A; 12 | boolean exp; 13 | 14 | @Test 15 | void zerosTestCase() { 16 | // ----------------- sub-case 1 ----------------- 17 | aEntries = new double[46][101]; 18 | A = new Matrix(aEntries); 19 | exp = true; 20 | 21 | Assertions.assertEquals(exp, A.isZeros()); 22 | 23 | // ----------------- sub-case 2 ----------------- 24 | aEntries = new double[46][101]; 25 | aEntries[21][9] = 1.324; 26 | A = new Matrix(aEntries); 27 | exp = false; 28 | 29 | Assertions.assertEquals(exp, A.isZeros()); 30 | } 31 | 32 | 33 | @Test 34 | void onesTestCase() { 35 | // ----------------- sub-case 1 ----------------- 36 | aEntries = new double[46][101]; 37 | ArrayBuilder.fill(aEntries, 1.0); 38 | A = new Matrix(aEntries); 39 | exp = true; 40 | 41 | Assertions.assertEquals(exp, A.isOnes()); 42 | 43 | // ----------------- sub-case 2 ----------------- 44 | aEntries = new double[46][101]; 45 | ArrayBuilder.fill(aEntries, 1.0); 46 | aEntries[21][9] = -1; 47 | A = new Matrix(aEntries); 48 | exp = false; 49 | 50 | Assertions.assertEquals(exp, A.isOnes()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/tensor/TensorAggregateTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.tensor; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.arrays.dense.Tensor; 5 | import org.junit.jupiter.api.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | class TensorAggregateTests { 11 | 12 | static Shape shape; 13 | static double[] entries; 14 | static Tensor A; 15 | static Double exp; 16 | static int[] expIndices; 17 | 18 | @BeforeAll 19 | static void setup() { 20 | entries = new double[]{1.234, 25.236, 6466.6, -0.0013, -8983.56, -0.01, 1.5, -99.3556, 12.56, 14.5, 11.6, -0.456}; 21 | shape = new Shape(1, 2, 3, 1, 2); 22 | A = new Tensor(shape, entries); 23 | } 24 | 25 | 26 | // @Test 27 | // void minMaxTestCase() { 28 | // Tensor empty = new Tensor(new Shape(0), new double[]{}); 29 | // 30 | // // -------------------------- Minimum Tests -------------------------- 31 | // exp = -8983.56; 32 | // assertEquals(exp, A.min()); 33 | // exp = 0.0013; 34 | // assertEquals(exp, A.minAbs()); 35 | // expIndices = shape.getIndices(4); 36 | // assertArrayEquals(expIndices, A.argmin()); 37 | // 38 | // assertArrayEquals(new int[]{}, empty.argmin()); 39 | // 40 | // // -------------------------- Maximum Tests -------------------------- 41 | // exp = 6466.6; 42 | // assertEquals(exp, A.max()); 43 | // exp = 8983.56; 44 | // assertEquals(exp, A.maxAbs()); 45 | // expIndices = shape.getIndices(2); 46 | // assertArrayEquals(expIndices, A.argmax()); 47 | // 48 | // assertArrayEquals(new int[]{}, empty.argmax()); 49 | // } 50 | 51 | 52 | @Test 53 | void sumTestCase() { 54 | // -------------------------- sub-case 1 -------------------------- 55 | exp = 1.234+25.236+6466.6-0.0013-8983.56-0.01+1.5-99.3556+12.56+14.5+11.6-0.456; 56 | assertEquals(exp, A.sum()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/tensor/TensorToStringTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.tensor; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.arrays.dense.Tensor; 5 | import org.flag4j.io.PrintOptions; 6 | import org.junit.jupiter.api.AfterEach; 7 | import org.junit.jupiter.api.BeforeAll; 8 | import org.junit.jupiter.api.Test; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | class TensorToStringTests { 13 | 14 | static Shape aShape; 15 | static double[] aEntries; 16 | static Tensor A; 17 | static String exp; 18 | 19 | @BeforeAll 20 | static void setup() { 21 | PrintOptions.resetAll(); 22 | aShape = new Shape(2, 3, 1, 2); 23 | aEntries = new double[]{1, -1.4133, 113.4, 0.4, 11.3, 445, 133.445, 9.8, 13384, -993.44, 11, 12}; 24 | A = new Tensor(aShape, aEntries); 25 | } 26 | 27 | 28 | @AfterEach 29 | void cleanup() { 30 | PrintOptions.resetAll(); 31 | } 32 | 33 | 34 | @Test 35 | void toStringTestCase() { 36 | PrintOptions.resetAll(); 37 | // ---------------------- sub-case 1 ---------------------- 38 | exp = "shape: (2, 3, 1, 2)\n" + 39 | "[ 1 -1.4133 113.4 0.4 11.3 445 133.445 9.8 13384 ... 12 ]"; 40 | assertEquals(exp, A.toString()); 41 | 42 | // ---------------------- sub-case 2 ---------------------- 43 | PrintOptions.setMaxColumns(15); 44 | PrintOptions.setPrecision(2); 45 | PrintOptions.setCentering(false); 46 | exp = "shape: (2, 3, 1, 2)\n" + 47 | "[1 -1.41 113.4 0.4 11.3 445 133.45 9.8 13384 -993.44 11 12 ]"; 48 | assertEquals(exp, A.toString()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/tensor/TensorUnitaryOperationTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.tensor; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.arrays.dense.Tensor; 5 | import org.junit.jupiter.api.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | class TensorUnitaryOperationTests { 11 | 12 | static double[] aEntries, expEntries; 13 | static Shape aShape, expShape; 14 | static Tensor A, exp; 15 | 16 | 17 | @BeforeAll 18 | static void setup() { 19 | aEntries = new double[]{ 20 | 0.000123, 5.23523, -834513.36, 235.6, 21 | 934, 13.5, -0.0, 0.1, 22 | 345, 8345.6, 1.00015, Double.POSITIVE_INFINITY}; 23 | aShape = new Shape(3, 2, 2); 24 | A = new Tensor(aShape, aEntries); 25 | } 26 | 27 | 28 | @Test 29 | void sqrtTestCase() { 30 | // --------------------- sub-case 1 --------------------- 31 | expEntries = new double[]{ 32 | Math.sqrt(0.000123), Math.sqrt(5.23523), Math.sqrt(-834513.36), Math.sqrt(235.6), 33 | Math.sqrt(934), Math.sqrt(13.5), Math.sqrt(-0.0), Math.sqrt(0.1), 34 | Math.sqrt(345), Math.sqrt(8345.6), Math.sqrt(1.00015), Math.sqrt(Double.POSITIVE_INFINITY)}; 35 | expShape = aShape; 36 | exp = new Tensor(expShape, expEntries); 37 | 38 | assertEquals(exp, A.sqrt()); 39 | } 40 | 41 | 42 | @Test 43 | void absTestCase() { 44 | // --------------------- sub-case 1 --------------------- 45 | expEntries = new double[]{ 46 | Math.abs(0.000123), Math.abs(5.23523), Math.abs(-834513.36), Math.abs(235.6), 47 | Math.abs(934), Math.abs(13.5), Math.abs(-0.0), Math.abs(0.1), 48 | Math.abs(345), Math.abs(8345.6), Math.abs(1.00015), Math.abs(Double.POSITIVE_INFINITY)}; 49 | expShape = aShape; 50 | exp = new Tensor(expShape, expEntries); 51 | 52 | assertEquals(exp, A.abs()); 53 | } 54 | 55 | 56 | @Test 57 | void recipTestCase() { 58 | // --------------------- sub-case 1 --------------------- 59 | expEntries = new double[]{ 60 | 1/(0.000123), 1/(5.23523), 1/(-834513.36), 1/(235.6), 61 | 1/(934.0), 1/(13.5), 1/(-0.0), 1/(0.1), 62 | 1/(345.0), 1/(8345.6), 1/(1.00015), 1/(Double.POSITIVE_INFINITY)}; 63 | expShape = aShape; 64 | exp = new Tensor(expShape, expEntries); 65 | 66 | assertEquals(exp, A.recip()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/dense/vector/VectorCopyTransposeTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.dense.vector; 2 | 3 | import org.flag4j.arrays.dense.Vector; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | import static org.junit.jupiter.api.Assertions.assertTrue; 8 | 9 | class VectorCopyTransposeTests { 10 | 11 | double[] aEntries, expEntries; 12 | Vector a, exp, act; 13 | 14 | @Test 15 | void copyTestCase() { 16 | aEntries = new double[]{234.45, -0.0234, Double.POSITIVE_INFINITY, Double.NaN, -0.0, 1}; 17 | a = new Vector(aEntries); 18 | expEntries = new double[]{234.45, -0.0234, Double.POSITIVE_INFINITY, Double.NaN, -0.0, 1}; 19 | exp = new Vector(expEntries); 20 | 21 | // ------------------ sub-case 1 ------------------ 22 | act = a.copy(); 23 | 24 | for(int i=0; ia.reshape(new Shape(sparseSize-2))); 50 | assertThrows(TensorShapeException.class, ()->a.reshape(sparseSize+32)); 51 | assertThrows(LinearAlgebraException.class, ()->a.flatten(-35)); 52 | assertThrows(LinearAlgebraException.class, ()->a.flatten(1)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/sparse/sparse_vector/CooVectorAggregateTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.sparse.sparse_vector; 2 | 3 | import org.flag4j.arrays.sparse.CooVector; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | class CooVectorAggregateTests { 10 | 11 | static double[] aValues; 12 | static int[] aIndices; 13 | static int size; 14 | static CooVector a; 15 | 16 | 17 | @BeforeAll 18 | static void setup() { 19 | aValues = new double[]{1.34, 51.6, -0.00245}; 20 | aIndices = new int[]{0, 5, 103}; 21 | size = 304; 22 | a = new CooVector(size, aValues, aIndices); 23 | } 24 | 25 | 26 | @Test 27 | void sumTestCase() { 28 | double exp; 29 | 30 | // --------------------- sub-case 1 --------------------- 31 | exp = 1.34+51.6-0.00245; 32 | assertEquals(exp, a.sum()); 33 | } 34 | 35 | 36 | // @Test 37 | // void argminMaxTestCase() { 38 | // int[] exp; 39 | // 40 | // // --------------------- sub-case 1 --------------------- 41 | // exp = new int[]{5}; 42 | // assertArrayEquals(exp, a.argmax()); 43 | // 44 | // exp = new int[]{103}; 45 | // assertArrayEquals(exp, a.argmin()); 46 | // } 47 | 48 | 49 | // @Test 50 | // void normTestCase() { 51 | // double exp; 52 | // 53 | // // --------------------- sub-case 1 --------------------- 54 | // exp = 51.61739635047955; 55 | // assertEquals(exp, VectorNorms.norm(a)); 56 | // 57 | // // --------------------- sub-case 2 --------------------- 58 | // exp = 51.82204923335818; 59 | // assertEquals(exp, VectorNorms.norm(a, 1.4)); 60 | // 61 | // // --------------------- sub-case 3 --------------------- 62 | // exp = 51.599999999999994; 63 | // assertEquals(exp, VectorNorms.norm(a, 23)); 64 | // 65 | // // --------------------- sub-case 4 --------------------- 66 | // exp = 152.7777441673176; 67 | // assertEquals(exp, VectorNorms.norm(a, 0.3)); 68 | // 69 | // // --------------------- sub-case 5 --------------------- 70 | // exp = 51.6; 71 | // assertEquals(exp, VectorNorms.norm(a, Double.POSITIVE_INFINITY)); 72 | // 73 | // // --------------------- sub-case 6 --------------------- 74 | // exp = 51.6; 75 | // assertEquals(exp, VectorNorms.infNorm(a)); 76 | // } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/sparse/sparse_vector/CooVectorReshapeTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.sparse.sparse_vector; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.arrays.sparse.CooVector; 5 | import org.flag4j.util.exceptions.LinearAlgebraException; 6 | import org.flag4j.util.exceptions.TensorShapeException; 7 | import org.junit.jupiter.api.BeforeAll; 8 | import org.junit.jupiter.api.Test; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | import static org.junit.jupiter.api.Assertions.assertThrows; 12 | 13 | class CooVectorReshapeTests { 14 | 15 | static CooVector a; 16 | CooVector exp; 17 | 18 | @BeforeAll 19 | static void setup() { 20 | double[] values = {1.34, 51.6, -0.00245}; 21 | int[] indices = {0, 5, 103}; 22 | int size = 304; 23 | a = new CooVector(size, values, indices); 24 | } 25 | 26 | @Test 27 | void reshapeTestCase() { 28 | double[] values = {1.34, 51.6, -0.00245}; 29 | int[] indices = {0, 5, 103}; 30 | int size = 304; 31 | 32 | // -------------------- sub-case 1 -------------------- 33 | exp = new CooVector(size, values, indices); 34 | assertEquals(exp, a.reshape(new Shape(size))); 35 | 36 | // -------------------- sub-case 2 -------------------- 37 | exp = new CooVector(size, values, indices); 38 | assertEquals(exp, a.reshape(size)); 39 | 40 | // -------------------- sub-case 3 -------------------- 41 | exp = new CooVector(size, values, indices); 42 | assertEquals(exp, a.flatten()); 43 | 44 | // -------------------- sub-case 4 -------------------- 45 | exp = new CooVector(size, values, indices); 46 | assertEquals(exp, a.flatten(0)); 47 | 48 | // -------------------- sub-case 5 -------------------- 49 | assertThrows(TensorShapeException.class, ()->a.reshape(new Shape(size-3))); 50 | 51 | // -------------------- sub-case 6 -------------------- 52 | assertThrows(TensorShapeException.class, ()->a.reshape(size-3)); 53 | 54 | // -------------------- sub-case 7 -------------------- 55 | assertThrows(LinearAlgebraException.class, ()->a.flatten(1)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/sparse/sparse_vector/CooVectorSetTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.sparse.sparse_vector; 2 | 3 | import org.flag4j.arrays.sparse.CooVector; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | class CooVectorSetTests { 10 | 11 | static CooVector a; 12 | CooVector exp; 13 | 14 | @BeforeAll 15 | static void setup() { 16 | double[] values = {1.34, 51.6, -0.00245}; 17 | int[] indices = {0, 5, 103}; 18 | int size = 304; 19 | a = new CooVector(size, values, indices); 20 | } 21 | 22 | @Test 23 | void setTestCase() { 24 | double[] values; 25 | int[] indices; 26 | int size; 27 | 28 | // -------------------- sub-case 1 -------------------- 29 | values = new double[]{1.34, 51.6, 22.34, -0.00245}; 30 | indices = new int[]{0, 5, 78, 103}; 31 | size = 304; 32 | exp = new CooVector(size, values, indices); 33 | 34 | assertEquals(exp, a.set(22.34, 78)); 35 | 36 | // -------------------- sub-case 2 -------------------- 37 | values = new double[]{44.5, 51.6, -0.00245}; 38 | indices = new int[]{0, 5, 103}; 39 | size = 304; 40 | exp = new CooVector(size, values, indices); 41 | 42 | assertEquals(exp, a.set(44.5, 0)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/sparse/sparse_vector/CooVectorToStringTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.sparse.sparse_vector; 2 | 3 | import org.flag4j.arrays.sparse.CooVector; 4 | import org.flag4j.io.PrintOptions; 5 | import org.junit.jupiter.api.AfterAll; 6 | import org.junit.jupiter.api.BeforeAll; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | 11 | class CooVectorToStringTests { 12 | 13 | String exp; 14 | static CooVector a; 15 | 16 | @BeforeAll 17 | static void setup() { 18 | double[] nze = {1.34, 525, 63.7, -0.0234}; 19 | int size = 3056; 20 | int[] indices = {1, 567, 1567, 2506}; 21 | 22 | a = new CooVector(size, nze, indices); 23 | } 24 | 25 | 26 | @AfterAll 27 | static void cleanup() { 28 | // Reset all print options. 29 | PrintOptions.resetAll(); 30 | } 31 | 32 | 33 | @Test 34 | void toStringTestCase() { 35 | // --------------------- sub-case 1 --------------------- 36 | exp = """ 37 | shape: (3056) 38 | nnz: 4 39 | Non-zero data: [ 1.34 525 63.7 -0.0234 ] 40 | Indices: [ 1 567 1567 2506 ]"""; 41 | assertEquals(exp, a.toString()); 42 | 43 | // --------------------- sub-case 2 --------------------- 44 | PrintOptions.setCentering(false); 45 | PrintOptions.setMaxColumns(2); 46 | PrintOptions.setPrecision(2); 47 | exp = """ 48 | shape: (3056) 49 | nnz: 4 50 | Non-zero data: [1.34 ... -0.02 ] 51 | Indices: [1 ... 2506 ]"""; 52 | assertEquals(exp, a.toString()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/sparse/sparse_vector/CooVectorUnaryOpTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.sparse.sparse_vector; 2 | 3 | import org.flag4j.CustomAssertions; 4 | import org.flag4j.arrays.sparse.CooVector; 5 | import org.junit.jupiter.api.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | class CooVectorUnaryOpTests { 11 | 12 | static double[] aEntries, expEntries; 13 | static int[] aIndices, expIndices; 14 | static int sparseSize; 15 | static CooVector a, exp; 16 | 17 | 18 | @BeforeAll 19 | static void setup() { 20 | aEntries = new double[]{1.34, -8781.5, 145.4, 6.26, -234.5666, 7.35}; 21 | aIndices = new int[]{0, 1, 6, 44, 78, 80}; 22 | sparseSize = 82; 23 | a = new CooVector(sparseSize, aEntries, aIndices); 24 | } 25 | 26 | 27 | @Test 28 | void absTestCase() { 29 | // --------------------- sub-case 1 --------------------- 30 | expEntries = new double[]{1.34, 8781.5, 145.4, 6.26, 234.5666, 7.35}; 31 | expIndices = new int[]{0, 1, 6, 44, 78, 80}; 32 | exp = new CooVector(sparseSize, expEntries, expIndices); 33 | 34 | assertEquals(exp, a.abs()); 35 | } 36 | 37 | 38 | @Test 39 | void sqrtTestCase() { 40 | // --------------------- sub-case 1 --------------------- 41 | expEntries = new double[]{Math.sqrt(1.34), Double.NaN, Math.sqrt(145.4), 42 | Math.sqrt(6.26), Double.NaN, Math.sqrt(7.35)}; 43 | expIndices = new int[]{0, 1, 6, 44, 78, 80}; 44 | exp = new CooVector(sparseSize, expEntries, expIndices); 45 | 46 | CustomAssertions.assertEqualsNaN(exp, a.sqrt()); 47 | } 48 | 49 | 50 | @Test 51 | void transposeTestCase() { 52 | // --------------------- sub-case 1 --------------------- 53 | expEntries = new double[]{1.34, -8781.5, 145.4, 6.26, -234.5666, 7.35}; 54 | expIndices = new int[]{0, 1, 6, 44, 78, 80}; 55 | exp = new CooVector(sparseSize, expEntries, expIndices); 56 | 57 | assertEquals(exp, a.T()); 58 | } 59 | 60 | 61 | @Test 62 | void recipTestCase() { 63 | // --------------------- sub-case 1 --------------------- 64 | expEntries = new double[]{1.0/1.34, 1.0/-8781.5, 1.0/145.4, 1.0/6.26, 1.0/-234.5666, 1.0/7.35}; 65 | expIndices = new int[]{0, 1, 6, 44, 78, 80}; 66 | exp = new CooVector(sparseSize, expEntries, expIndices); 67 | 68 | assertEquals(exp, a.recip()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/arrays/sparse/sparse_vector/SparseVectorCooSortTest.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.arrays.sparse.sparse_vector; 2 | 3 | import org.flag4j.arrays.sparse.CooVector; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | class SparseVectorCooSortTest { 10 | static int[] aIndices, expIndices; 11 | static double[] aEntries, expEntries; 12 | static int sparseSize; 13 | static CooVector a, exp; 14 | 15 | 16 | @BeforeAll 17 | static void setup() { 18 | aEntries = new double[]{1.345, -989.234, 5.15, 617.4, 1.34, 5126.234, 456.3}; 19 | aIndices = new int[]{36, 13, 4, 11345, 3, 645, 3324}; 20 | sparseSize = 24_023; 21 | a = new CooVector(sparseSize, aEntries, aIndices); 22 | } 23 | 24 | 25 | @Test 26 | void sparseSortTestCase() { 27 | // --------------------- sub-case 1 --------------------- 28 | expIndices = new int[]{3, 4, 13, 36, 645, 3324, 11345}; 29 | expEntries = new double[]{1.34, 5.15, -989.234, 1.345, 5126.234, 456.3, 617.4}; 30 | exp = new CooVector(sparseSize, expEntries, expIndices); 31 | 32 | a.sortIndices(); 33 | assertEquals(exp, a); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/complex_numbers/Complex128GettersSettersTest.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.complex_numbers; 2 | 3 | import org.flag4j.numbers.Complex128; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | 7 | class Complex128GettersSettersTest { 8 | Complex128 num; 9 | long expReLong, expImLong; 10 | int expReInt, expImInt; 11 | float expReFloat, expImFloat; 12 | double expReDouble, expImDouble; 13 | 14 | 15 | @Test 16 | void gettersTestCase() { 17 | num = new Complex128(692.13, -9673.134); 18 | expReDouble = 692.13; 19 | expImDouble = -9673.134; 20 | 21 | Assertions.assertEquals(expReDouble, num.re()); 22 | Assertions.assertEquals(expImDouble, num.im()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/io/PrintOptionsTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class PrintOptionsTests { 8 | 9 | @Test 10 | void printOptionTestCase() { 11 | assertEquals(2, PrintOptions.getPadding()); 12 | assertEquals(10, PrintOptions.getMaxRows()); 13 | assertEquals(10, PrintOptions.getMaxColumns()); 14 | assertEquals(8, PrintOptions.getPrecision()); 15 | assertTrue(PrintOptions.useCentering()); 16 | 17 | PrintOptions.setPadding(14); 18 | PrintOptions.setMaxRows(15); 19 | PrintOptions.setMaxColumns(100); 20 | PrintOptions.setPrecision(134); 21 | PrintOptions.setCentering(false); 22 | 23 | assertEquals(14, PrintOptions.getPadding()); 24 | assertEquals(15, PrintOptions.getMaxRows()); 25 | assertEquals(100, PrintOptions.getMaxColumns()); 26 | assertEquals(134, PrintOptions.getPrecision()); 27 | assertFalse(PrintOptions.useCentering()); 28 | 29 | assertThrows(IllegalArgumentException.class, () -> PrintOptions.setPadding(-1)); 30 | assertThrows(IllegalArgumentException.class, () -> PrintOptions.setMaxRows(-1)); 31 | assertThrows(IllegalArgumentException.class, () -> PrintOptions.setMaxColumns(-1)); 32 | assertThrows(IllegalArgumentException.class, () -> PrintOptions.setPrecision(-1)); 33 | 34 | PrintOptions.resetAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/linalg/decompositions/ComplexCholeskyTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.linalg.decompositions; 2 | 3 | import org.flag4j.arrays.dense.CMatrix; 4 | import org.flag4j.linalg.decompositions.chol.ComplexCholesky; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | class ComplexCholeskyTests { 10 | 11 | static String[][] aEntries; 12 | static CMatrix A, L, A_hat; 13 | 14 | static void setMatrices() { 15 | A = new CMatrix(aEntries); 16 | } 17 | 18 | 19 | @Test 20 | void choleskyTestCase() { 21 | ComplexCholesky cholesky = new ComplexCholesky(); 22 | 23 | // --------------------- sub-case 1 --------------------- 24 | aEntries = new String[][]{ 25 | {"1", "-2i"}, 26 | {"2i", "5"}}; 27 | setMatrices(); 28 | 29 | L = cholesky.decompose(A).getL(); 30 | A_hat = L.mult(L.H()); 31 | 32 | assertEquals(new CMatrix(A.shape), A.sub(A_hat).roundToZero(1.0e-12)); 33 | 34 | // --------------------- sub-case 2 --------------------- 35 | aEntries = new String[][]{ 36 | {"2", "i"}, 37 | {"-i", "2"}}; 38 | setMatrices(); 39 | 40 | L = cholesky.decompose(A).getL(); 41 | A_hat = L.mult(L.H()); 42 | 43 | assertEquals(new CMatrix(A.shape), A.sub(A_hat).roundToZero(1.0e-12)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/linalg/decompositions/RealCholeskyTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.linalg.decompositions; 2 | 3 | import org.flag4j.arrays.dense.Matrix; 4 | import org.flag4j.linalg.decompositions.chol.RealCholesky; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class RealCholeskyTests { 9 | 10 | static double[][] aEntries; 11 | static double[][] expLEntries; 12 | 13 | static Matrix A; 14 | static Matrix expL; 15 | 16 | 17 | static void setMatrices() { 18 | A = new Matrix(aEntries); 19 | expL = new Matrix(expLEntries); 20 | } 21 | 22 | 23 | @Test 24 | void choleskyTestCase() { 25 | RealCholesky cholesky = new RealCholesky(); 26 | 27 | // --------------------- sub-case 1 --------------------- 28 | aEntries = new double[][]{ 29 | {2.0, -1.0, 0.0}, 30 | {-1.0, 2.0, -1.0}, 31 | {0.0, -1.0, 2.0}}; 32 | expLEntries = new double[][]{ 33 | {1.4142135623730951, 0.0, 0.0}, 34 | {-0.7071067811865475, 1.224744871391589, 0.0}, 35 | {0.0, -0.8164965809277261, 1.1547005383792515}}; 36 | setMatrices(); 37 | 38 | cholesky.decompose(A); 39 | Assertions.assertEquals(expL, cholesky.getL()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/linalg/decompositions/RealSchurTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.linalg.decompositions; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.arrays.dense.CMatrix; 5 | import org.flag4j.arrays.dense.Matrix; 6 | import org.flag4j.linalg.decompositions.schur.RealSchur; 7 | import org.junit.jupiter.api.BeforeAll; 8 | import org.junit.jupiter.api.Test; 9 | 10 | class RealSchurTests { 11 | static final long SEED = 0xC0DE; 12 | 13 | static Shape aShape; 14 | static double[] aData; 15 | static Matrix a; 16 | static Matrix U; 17 | static Matrix T; 18 | static CMatrix[] TUcm; 19 | 20 | static RealSchur schur; 21 | static RealSchur schurU; 22 | 23 | @BeforeAll 24 | static void setUp() { 25 | schurU = new RealSchur(true, SEED); 26 | schur = new RealSchur(false, SEED); 27 | } 28 | 29 | @Test 30 | void realSchurTests() { 31 | // // ----------------- sub-case 1 ----------------- 32 | // aShape = new Shape(11, 11); 33 | // aData = new double[]{1e-08, 0.02, 0.0, 5e-05, 30000.0, 0.0, -1000.0, 0.0, 70.0, 0.0, 9000000.0, 5000.0, 100.0, -0.002, 0.0, 34 | // 0.0, 0.0, 9e-09, 0.0, 0.0, -300000.0, 200.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1e-09, 35 | // 100000000.0, -10.0, 0.0, 0.0, 40.0, 0.0, 0.0, 0.0, -0.0003, 40000.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -400.0, 0.0, 10.0, 36 | // 200.0, 0.0, 200000.0, 0.0, 1e-05, 0.0, 0.0, 0.0, 0.0, 5e-06, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2000000000.0, 0.0, 37 | // 0.0, 0.0, 0.0, 0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.005, 0.0002, 1e-07, 0.0, 0.0, 10.0, 0.0, -90000.0, 0.0, 3e-06, 0.0, 38 | // 0.0, 0.0, 300000000.0, 0.0, 0.0, 0.0, 0.0005, 0.0, 0.0, 10000.0, 0.0, 0.0, 0.0, 0.0, 1e-08, 200000.0, 7000.0, 0.0, 39 | // 0.0, 0.2, 0.0, 0.0, 1000.0, 0.0, 0.0, -400.0, 0.01}; 40 | // a = new Matrix(aShape, aData); 41 | // 42 | // // TODO: TEMP FOR TESTING 43 | // PrintOptions.setMaxRowsCols(100); 44 | // TestHelpers.printAsJavaArray(a); 45 | // // TODO: END OF TEMP 46 | // 47 | // schurU.decompose(a); 48 | // U = schurU.getU(); 49 | // T = schurU.getT(); 50 | // TUcm = schurU.real2ComplexSchur(); 51 | // 52 | // assertTrue(TUcm[0].isTriU()); 53 | // assertTrue(TUcm[1].isOrthogonal()); 54 | // CustomAssertions.assertEquals(a, TUcm[1].mult(TUcm[0]).mult(TUcm[1].H()).toReal(), 1.0e-12); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/linalg/ops/common/real/unaryOperationTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.linalg.ops.common.real; 2 | 3 | 4 | import org.flag4j.arrays.dense.Matrix; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | class unaryOperationTests { 10 | 11 | double[][] aEntries, expEntries; 12 | Matrix A, exp; 13 | 14 | @Test 15 | void sqrtTestCase() { 16 | // ---------------- sub-case 1 ---------------- 17 | aEntries = new double[][]{{1.334, 5, 16}, {-134.5, 66.236, 144}}; 18 | A = new Matrix(aEntries); 19 | expEntries = new double[][]{{Math.sqrt(1.334), Math.sqrt(5), Math.sqrt(16)}, 20 | {Math.sqrt(-134.5), Math.sqrt(66.236), Math.sqrt(144)}}; 21 | exp = new Matrix(expEntries); 22 | 23 | assertEquals(exp, A.sqrt()); 24 | } 25 | 26 | @Test 27 | void absTestCase() { 28 | // ---------------- sub-case 1 ---------------- 29 | aEntries = new double[][]{{-1.334, 5, 16}, {-134.5, 66.236, 144}}; 30 | A = new Matrix(aEntries); 31 | expEntries = new double[][]{{1.334, 5, 16}, {134.5, 66.236, 144}}; 32 | exp = new Matrix(expEntries); 33 | 34 | assertEquals(exp, A.abs()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/linalg/ops/dense_sparse/real/RealDenseSparseMatMultTransposeTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.linalg.ops.dense_sparse.real; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.arrays.dense.Matrix; 5 | import org.flag4j.arrays.sparse.CooMatrix; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.flag4j.linalg.ops.dense_sparse.coo.real.RealDenseSparseMatrixMultTranspose.multTranspose; 9 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 10 | 11 | class RealDenseSparseMatMultTransposeTests { 12 | double[] bEntries; 13 | int[] rowIndices, colIndices; 14 | CooMatrix B; 15 | Shape bShape; 16 | 17 | double[][] aEntries; 18 | Matrix A, exp; 19 | 20 | @Test 21 | void matMultTestCase() { 22 | // ---------------------- sub-case 1 ---------------------- 23 | aEntries = new double[][]{ 24 | {1.1234, 99.234, 0.000123}, 25 | {-932.45, 551.35, -0.92342}, 26 | {123.445, 0.00013, 0.0}, 27 | {78.234, 12.234, -9923.23}}; 28 | A = new Matrix(aEntries); 29 | bEntries = new double[]{-0.9345341, 11.67}; 30 | rowIndices = new int[]{0, 1}; 31 | colIndices = new int[]{1, 2}; 32 | bShape = new Shape(2, 3); 33 | B = new CooMatrix(bShape, bEntries, rowIndices, colIndices); 34 | exp = A.mult(new CooMatrix(bShape.swapAxes(0, 1), bEntries, colIndices, rowIndices)); 35 | 36 | assertArrayEquals(exp.data, multTranspose(A.data, A.shape, B.data, B.rowIndices, B.colIndices, B.shape)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/linalg/ops/sparse/coo/real/RealSpareMatrixAddTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.linalg.ops.sparse.coo.real; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.arrays.sparse.CooMatrix; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | class RealSpareMatrixAddTests { 10 | 11 | int[][] aIndices, bIndices, expIndices; 12 | double[] aEntries, bEntries, expEntries; 13 | CooMatrix A, B, exp; 14 | Shape aShape, bShape, expShape; 15 | 16 | 17 | @Test 18 | void addTestCase() { 19 | // ------------------- sub-case 1 ------------------- 20 | aShape = new Shape(2025, 10005); 21 | aEntries = new double[]{1.144, -99.25, 1.566, 0.00356, 100.36, 9954.256, 345.2}; 22 | aIndices = new int[][]{ 23 | {0, 25, 502, 502, 789, 1003, 2008}, 24 | {9892, 0, 9, 608, 92, 608, 26} 25 | }; 26 | A = new CooMatrix(aShape, aEntries, aIndices[0], aIndices[1]); 27 | 28 | bShape = new Shape(2025, 10005); 29 | bEntries = new double[]{-9.456, 234.6, -22.0044, 88.3216}; 30 | bIndices = new int[][]{ 31 | {0, 25, 502, 2014}, 32 | {9892, 902, 3, 14} 33 | }; 34 | B = new CooMatrix(bShape, bEntries, bIndices[0], bIndices[1]); 35 | 36 | expShape = new Shape(2025, 10005); 37 | expEntries = new double[]{1.144-9.456, -99.25, 234.6, -22.0044, 38 | 1.566, 0.00356, 100.36, 9954.256, 345.2, 88.3216}; 39 | expIndices = new int[][]{ 40 | {0, 25, 25, 502, 502, 502, 789, 1003, 2008, 2014}, 41 | {9892, 0, 902, 3, 9, 608, 92, 608, 26, 14} 42 | }; 43 | exp = new CooMatrix(expShape, expEntries, expIndices[0], expIndices[1]); 44 | 45 | 46 | assertEquals(exp, RealSparseMatrixOps.add(A, B)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/numbers/bool_semirings/ConstructorConstantsTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.numbers.bool_semirings; 2 | 3 | import org.flag4j.numbers.BoolSemiring; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class ConstructorConstantsTests { 9 | 10 | 11 | @Test 12 | void constructorTestCase() { 13 | BoolSemiring act; 14 | boolean exp; 15 | 16 | // --------------- sub-case 1 --------------- 17 | act = new BoolSemiring(true); 18 | assertTrue(act.getValue()); 19 | 20 | // --------------- sub-case 2 --------------- 21 | act = new BoolSemiring(false); 22 | assertFalse(act.getValue()); 23 | 24 | // --------------- sub-case 3 --------------- 25 | act = new BoolSemiring(1); 26 | assertTrue(act.getValue()); 27 | 28 | // --------------- sub-case 4 --------------- 29 | act = new BoolSemiring(0); 30 | assertFalse(act.getValue()); 31 | 32 | // --------------- sub-case 5 --------------- 33 | assertThrows(IllegalArgumentException.class, () -> new BoolSemiring(2)); 34 | assertThrows(IllegalArgumentException.class, () -> new BoolSemiring(-1)); 35 | assertThrows(IllegalArgumentException.class, () -> new BoolSemiring(1002)); 36 | } 37 | 38 | 39 | @Test 40 | void constantTestCase() { 41 | // --------------- sub-case 1 --------------- 42 | assertTrue(BoolSemiring.TRUE.getValue()); 43 | assertTrue(BoolSemiring.ONE.getValue()); 44 | assertTrue(new BoolSemiring(0).getOne().getValue()); 45 | assertTrue(new BoolSemiring(1).isOne()); 46 | assertTrue(new BoolSemiring(0).isZero()); 47 | assertFalse(BoolSemiring.ZERO.getValue()); 48 | assertFalse(BoolSemiring.FALSE.getValue()); 49 | assertFalse(new BoolSemiring(1).getZero().getValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/numbers/fields/Complex64GettersSettersTest.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.numbers.fields; 2 | 3 | import org.flag4j.numbers.Complex64; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | 7 | class Complex64GettersSettersTest { 8 | Complex64 num; 9 | long expReLong, expImLong; 10 | int expReInt, expImInt; 11 | float expReFloat, expImFloat; 12 | 13 | 14 | @Test 15 | void gettersTestCase() { 16 | num = new Complex64(692.13f, -9673.134f); 17 | expReFloat = 692.13f; 18 | expImFloat = -9673.134f; 19 | 20 | Assertions.assertEquals(expReFloat, num.re()); 21 | Assertions.assertEquals(expImFloat, num.im()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/util/ErrorMessagesTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.util; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | class ErrorMessagesTests { 11 | Shape s1, s2; 12 | String expMsg; 13 | 14 | 15 | @Test 16 | void EqualShapeErrMsgTestCase() { 17 | // --------- sub-case 1 --------- 18 | s1 = new Shape(2); 19 | s2 = new Shape(5); 20 | expMsg = String.format("Expecting tensors to have the same shape but got %s and %s.", 21 | "(2)", "(5)"); 22 | 23 | assertEquals(expMsg, ErrorMessages.equalShapeErrMsg(s1, s2)); 24 | 25 | 26 | // --------- sub-case 2 --------- 27 | s1 = new Shape(1, 2, 3, 4); 28 | s2 = new Shape(4, 3, 2, 1); 29 | expMsg = String.format("Expecting tensors to have the same shape but got %s and %s.", 30 | "(1, 2, 3, 4)", "(4, 3, 2, 1)"); 31 | 32 | assertEquals(expMsg, ErrorMessages.equalShapeErrMsg(s1, s2)); 33 | } 34 | 35 | 36 | @Test 37 | void matMultShapeErrMsgTestCase() { 38 | // --------- sub-case 1 --------- 39 | s1 = new Shape(10, 5); 40 | s2 = new Shape(14, 4); 41 | expMsg = String.format("Cannot multiply matrices/vector with shapes (10, 5) and (14, 4)."); 42 | 43 | assertEquals(expMsg, ErrorMessages.matMultShapeErrMsg(s1, s2)); 44 | } 45 | 46 | 47 | @Test 48 | void negativeDimErrMsgTestCase() { 49 | int[] dims = {-1, 1}; 50 | expMsg = String.format("Shape dimensions must be non-negative but got shape %s.", 51 | Arrays.toString(dims)); 52 | 53 | assertEquals(expMsg, ErrorMessages.negativeDimErrMsg(dims)); 54 | } 55 | 56 | 57 | @Test 58 | void utilityClassErrMsgTestCase() { 59 | expMsg = "Utility class cannot be instantiated."; 60 | 61 | assertEquals(expMsg, ErrorMessages.getUtilityClassErrMsg()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/util/StringUtilsTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.util; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | class StringUtilsTests { 9 | 10 | int size; 11 | String pad; 12 | String str; 13 | String expStr; 14 | 15 | @Test 16 | void centerTestCase() { 17 | // --------------- sub-case 1 --------------- 18 | size = 13; 19 | str = "hello world"; 20 | expStr = " hello world "; 21 | assertEquals(expStr, StringUtils.center(str, size)); 22 | 23 | // --------------- sub-case 2 --------------- 24 | size = 5; 25 | str = "hello world"; 26 | expStr = "hello world"; 27 | assertEquals(expStr, StringUtils.center(str, size)); 28 | 29 | // --------------- sub-case 3 --------------- 30 | size = 17; 31 | str = "hello world"; 32 | expStr = " hello world "; 33 | assertEquals(expStr, StringUtils.center(str, size)); 34 | 35 | // --------------- sub-case 4 --------------- 36 | size = 13; 37 | pad = "-"; 38 | str = "hello world"; 39 | expStr = "-hello world-"; 40 | assertEquals(expStr, StringUtils.center(str, size, pad)); 41 | 42 | // --------------- sub-case 5 --------------- 43 | size = 5; 44 | pad = "-"; 45 | str = "hello world"; 46 | expStr = "hello world"; 47 | assertEquals(expStr, StringUtils.center(str, size, pad)); 48 | 49 | // --------------- sub-case 6 --------------- 50 | size = 17; 51 | pad = "-"; 52 | str = "hello world"; 53 | expStr = "---hello world---"; 54 | assertEquals(expStr, StringUtils.center(str, size, pad)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/flag4j/util/ValidateParametersTests.java: -------------------------------------------------------------------------------- 1 | package org.flag4j.util; 2 | 3 | import org.flag4j.arrays.Shape; 4 | import org.flag4j.util.exceptions.LinearAlgebraException; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertThrows; 8 | 9 | class ValidateParametersTests { 10 | Shape shape1, shape2; 11 | 12 | @Test 13 | void matMultTestCase() { 14 | // ------------ sub-case 1 ------------ 15 | shape1 = new Shape(5, 5); 16 | shape2 = new Shape(5, 5); 17 | 18 | ValidateParameters.ensureMatMultShapes(shape1, shape2); 19 | 20 | // ------------ sub-case 2 ------------ 21 | shape1 = new Shape(5, 1); 22 | shape2 = new Shape(1, 5); 23 | 24 | ValidateParameters.ensureMatMultShapes(shape1, shape2); 25 | 26 | // ------------ sub-case 3 ------------ 27 | shape1 = new Shape(1, 5); 28 | shape2 = new Shape(1, 5); 29 | 30 | assertThrows(LinearAlgebraException.class, 31 | ()-> ValidateParameters.ensureMatMultShapes(shape1, shape2)); 32 | 33 | // ------------ sub-case 4 ------------ 34 | shape1 = new Shape(6, 114); 35 | shape2 = new Shape(114, 6); 36 | 37 | ValidateParameters.ensureMatMultShapes(shape1, shape2); 38 | 39 | // ------------ sub-case 5 ------------ 40 | shape1 = new Shape(112, 1, 1); 41 | shape2 = new Shape(113); 42 | assertThrows(LinearAlgebraException.class, 43 | ()-> ValidateParameters.ensureMatMultShapes(shape1, shape2)); 44 | } 45 | } 46 | --------------------------------------------------------------------------------