1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
25 std::unique_ptr
<std::unique_ptr
<double[]>[]> mgcLinearSystemD::NewMatrix (int N
)
27 std::unique_ptr
<std::unique_ptr
<double[]>[]> A(new std::unique_ptr
<double[]>);
29 for (int row
= 0; row
< N
; row
++)
31 A
[row
].reset(new double[N
]);
32 for (int col
= 0; col
< N
; col
++)
38 std::unique_ptr
<double[]> mgcLinearSystemD::NewVector (int N
)
40 std::unique_ptr
<double[]> B(new double[N
]);
42 for (int row
= 0; row
< N
; row
++)
47 bool mgcLinearSystemD::Solve (int n
, std::unique_ptr
<std::unique_ptr
<double[]>[]> const & a
, double* b
)
49 std::unique_ptr
<int[]> indxc( new int[n
] );
50 std::unique_ptr
<int[]> indxr( new int[n
] );
51 std::unique_ptr
<int[]> ipiv( new int[n
] );
58 for (j
= 0; j
< n
; j
++)
61 for (i
= 0; i
< n
; i
++)
64 for (j
= 0; j
< n
; j
++)
68 for (k
= 0; k
< n
; k
++)
72 if ( fabs(a
[j
][k
]) >= big
)
79 else if ( ipiv
[k
] > 1 )
90 std::swap(a
[irow
], a
[icol
]);
99 if ( a
[icol
][icol
] == 0 )
104 double pivinv
= 1/a
[icol
][icol
];
106 for (k
= 0; k
< n
; k
++)
107 a
[icol
][k
] *= pivinv
;
110 for (j
= 0; j
< n
; j
++)
116 for (k
= 0; k
< n
; k
++)
117 a
[j
][k
] -= a
[icol
][k
]*save
;
118 b
[j
] -= b
[icol
]*save
;
123 for (j
= n
-1; j
>= 0; j
--)
125 if ( indxr
[j
] != indxc
[j
] )
127 for (k
= 0; k
< n
; k
++)
129 save
= a
[k
][indxr
[j
]];
130 a
[k
][indxr
[j
]] = a
[k
][indxc
[j
]];
131 a
[k
][indxc
[j
]] = save
;
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */