-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new numerical methods to solve linear system: #531
base: dev
Are you sure you want to change the base?
Conversation
1. Thomas method (прогонки) 2. Jacobi method (iterative) 3. Seidel method (iterative, improvement version of the Jacobi method)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods should use LinearAlgebra and generalized for non-Float64 types.
Also, please add an example of usage in example
module and a short markdown documentation on when those methods should be used.
* @return vector X - solution of the system 'A*X=B'. | ||
*/ | ||
@UnstableKMathAPI | ||
public fun solveSystemByJacobiMethod( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global namespace polution. The method must be made an extension for something. Using Double-only methods is not a KMath way, one should use Field
or Ring
if one does not need division for that.
private var cachedMachineEpsilonPrecision: Double? = null | ||
|
||
@UnstableKMathAPI | ||
public val machineEpsilonPrecision: Double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global namespace polution. And it should be Algebra attribute.
} | ||
} | ||
|
||
var X: Point<Double> = initialApproximation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style violation
return X | ||
} | ||
|
||
private fun calcNorm(x1: Point<Double>, x2: Point<Double>): Double { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function could be moved inside the only function it is used in
|
||
norm = calcNorm(X, xTmp) | ||
X = xTmp | ||
} while (norm > epsilonPrecision) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be infinite?
} | ||
} | ||
|
||
val X: MutableStructure1D<Double> = initialApproximation?.let { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style violation.
return X | ||
} | ||
|
||
private fun calcNorm(x1: Point<Double>, x2: Point<Double>): Double { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function duplicate
* @return vector X - solution of the system 'A*X=B'. | ||
*/ | ||
@UnstableKMathAPI | ||
public fun solveSystemByThomasMethod( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global namespace pollution and unnecessary specialization. The same as above.
) | ||
|
||
assertEquals(4, result.size) | ||
val absoluteTolerance = 0.00000000000001 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test method for structure equality
*/ | ||
@Test | ||
fun exceptionTest1() = | ||
Double.algebra.linearSpace.run { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like with
more
and unit tests.