File size: 4,388 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#region Translated by Jose Antonio De Santiago-Castillo.

//Translated by Jose Antonio De Santiago-Castillo.
//E-mail:JAntonioDeSantiago@gmail.com
//Website: www.DotNumerics.com
//
//Fortran to C# Translation.
//Translated by:
//F2CSharp Version 0.72 (Dicember 7, 2009)
//Code Optimizations: , assignment operator, for-loop: array indexes
//
#endregion

using System;
using DotNumerics.FortranLibrary;

namespace DotNumerics.Optimization.LBFGSB
{
    public class FORMT
    {
    

        #region Dependencies
        
        DPOFA _dpofa; 

        #endregion


        #region Variables
        
        const double ZERO = 0.0E0; 

        #endregion

        public FORMT(DPOFA dpofa)
        {
    

            #region Set Dependencies
            
            this._dpofa = dpofa; 

            #endregion

        }
    
        public FORMT()
        {
    

            #region Dependencies (Initialization)
            
            DDOT ddot = new DDOT();
            DPOFA dpofa = new DPOFA(ddot);

            #endregion


            #region Set Dependencies
            
            this._dpofa = dpofa; 

            #endregion

        }
        public void Run(int M, ref double[] WT, int offset_wt, double[] SY, int offset_sy, double[] SS, int offset_ss, int COL, double THETA

                         , ref int INFO)
        {

            #region Variables
            
            int I = 0; int J = 0; int K = 0; int K1 = 0; double DDUM = 0; 

            #endregion


            #region Array Index Correction
            
             int o_wt = -1 - M + offset_wt;  int o_sy = -1 - M + offset_sy;  int o_ss = -1 - M + offset_ss; 

            #endregion


            #region Prolog
            
            
            
            // c     ************
            // c
            // c     Subroutine formt
            // c
            // c       This subroutine forms the upper half of the pos. def. and symm.
            // c         T = theta*SS + L*D^(-1)*L', stores T in the upper triangle
            // c         of the array wt, and performs the Cholesky factorization of T
            // c         to produce J*J', with J' stored in the upper triangle of wt.
            // c
            // c     Subprograms called:
            // c
            // c       Linpack ... dpofa.
            // c
            // c
            // c                           *  *  *
            // c
            // c     NEOS, November 1994. (Latest revision June 1996.)
            // c     Optimization Technology Center.
            // c     Argonne National Laboratory and Northwestern University.
            // c     Written by
            // c                        Ciyou Zhu
            // c     in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
            // c
            // c
            // c     ************
            
            
            
            
            
            // c     Form the upper half of  T = theta*SS + L*D^(-1)*L',
            // c        store T in the upper triangle of the array wt.
            

            #endregion


            #region Body
            
            for (J = 1; J <= COL; J++)
            {
                WT[1+J * M + o_wt] = THETA * SS[1+J * M + o_ss];
            }
            for (I = 2; I <= COL; I++)
            {
                for (J = I; J <= COL; J++)
                {
                    K1 = Math.Min(I, J) - 1;
                    DDUM = ZERO;
                    for (K = 1; K <= K1; K++)
                    {
                        DDUM += SY[I+K * M + o_sy] * SY[J+K * M + o_sy] / SY[K+K * M + o_sy];
                    }
                    WT[I+J * M + o_wt] = DDUM + THETA * SS[I+J * M + o_ss];
                }
            }
            
            // c     Cholesky factorize T to J*J' with 
            // c        J' stored in the upper triangle of wt.
            
            this._dpofa.Run(ref WT, offset_wt, M, COL, ref INFO);
            if (INFO != 0)
            {
                INFO =  - 3;
            }
            
            return;
            

            #endregion

        }
    }
    
    // c======================= The end of formt ==============================
}