GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
FixedOrderKernels.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
#pragma once
4
5
// Dense kernels whose rounding is a function of the operand values alone.
6
// Every output entry is formed by one fixed sequence of binary64 operations
7
// (inner index ascending, no reassociation, no fused multiply-add: the
8
// build passes -ffp-contract=off). The loops run over independent entries,
9
// so vectorization, alignment, blocking and threading cannot change a
10
// result. They carry the panel and diagonal work of the reproducible
11
// factorizations next to the exact Scheme II products.
12
13
#include <cmath>
14
#include <cstdint>
15
16
namespace
gpr::linalg::fixed
{
17
23
inline
bool
choleskyLower
(
double
* a, std::int64_t lda, std::int64_t n)
24
{
25
for
(std::int64_t j = 0; j < n; ++j) {
26
double
* column = a + j * lda;
27
for
(std::int64_t l = 0; l < j; ++l) {
28
const
double
* source = a + l * lda;
29
const
double
factor = source[j];
30
for
(std::int64_t i = j; i < n; ++i)
31
column[i] -= source[i] * factor;
32
}
33
const
double
pivot = column[j];
34
if
(!(pivot > 0.0) || !std::isfinite(pivot))
return
false
;
35
const
double
root = std::sqrt(pivot);
36
column[j] = root;
37
for
(std::int64_t i = j + 1; i < n; ++i)
38
column[i] /= root;
39
}
40
return
true
;
41
}
42
46
inline
void
solveRightLowerTranspose
(
const
double
* l, std::int64_t ldl,
47
std::int64_t n,
double
*
x
,
48
std::int64_t ldx, std::int64_t rows)
49
{
50
for
(std::int64_t c = 0; c < n; ++c) {
51
double
* column =
x
+ c * ldx;
52
for
(std::int64_t q = 0; q < c; ++q) {
53
const
double
factor = l[c + q * ldl];
54
const
double
* source =
x
+ q * ldx;
55
for
(std::int64_t i = 0; i < rows; ++i)
56
column[i] -= source[i] * factor;
57
}
58
const
double
pivot = l[c + c * ldl];
59
for
(std::int64_t i = 0; i < rows; ++i)
60
column[i] /= pivot;
61
}
62
}
63
67
inline
void
solveLeftTriangular
(
const
double
* t, std::int64_t ldt,
68
std::int64_t n,
bool
lower,
double
* b,
69
std::int64_t ldb, std::int64_t cols)
70
{
71
for
(std::int64_t j = 0; j < cols; ++j) {
72
double
*
x
= b + j * ldb;
73
if
(lower) {
74
for
(std::int64_t r = 0; r < n; ++r) {
75
x
[r] /= t[r + r * ldt];
76
const
double
solved =
x
[r];
77
const
double
* below = t + r * ldt;
78
for
(std::int64_t i = r + 1; i < n; ++i)
79
x
[i] -= below[i] * solved;
80
}
81
}
else
{
82
for
(std::int64_t r = n - 1; r >= 0; --r) {
83
x
[r] /= t[r + r * ldt];
84
const
double
solved =
x
[r];
85
const
double
* above = t + r * ldt;
86
for
(std::int64_t i = 0; i < r; ++i)
87
x
[i] -= above[i] * solved;
88
}
89
}
90
}
91
}
92
96
inline
void
subtractProduct
(
const
double
* a, std::int64_t lda,
bool
transpose_a,
97
const
double
* b, std::int64_t ldb,
double
* c,
98
std::int64_t ldc, std::int64_t m, std::int64_t n,
99
std::int64_t k)
100
{
101
for
(std::int64_t j = 0; j < n; ++j) {
102
double
*
out
= c + j * ldc;
103
for
(std::int64_t l = 0; l < k; ++l) {
104
const
double
factor = b[l + j * ldb];
105
if
(!transpose_a) {
106
const
double
* column = a + l * lda;
107
for
(std::int64_t i = 0; i < m; ++i)
108
out
[i] -= column[i] * factor;
109
}
else
{
110
for
(std::int64_t i = 0; i < m; ++i)
111
out
[i] -= a[l + i * lda] * factor;
112
}
113
}
114
}
115
}
116
120
inline
void
subtractProductTransposed
(
const
double
* a, std::int64_t lda,
121
const
double
* bt, std::int64_t ldbt,
122
double
* c, std::int64_t ldc,
123
std::int64_t m, std::int64_t n,
124
std::int64_t k)
125
{
126
for
(std::int64_t j = 0; j < n; ++j) {
127
double
*
out
= c + j * ldc;
128
for
(std::int64_t l = 0; l < k; ++l) {
129
const
double
factor = bt[j + l * ldbt];
130
const
double
* column = a + l * lda;
131
for
(std::int64_t i = 0; i < m; ++i)
132
out
[i] -= column[i] * factor;
133
}
134
}
135
}
136
137
}
// namespace gpr::linalg::fixed
x
@ x
Definition
Enums.h:28
out
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
Definition
eon_relax_engine.h:240
gpr::linalg::fixed
Definition
FixedOrderKernels.h:16
gpr::linalg::fixed::solveRightLowerTranspose
void solveRightLowerTranspose(const double *l, std::int64_t ldl, std::int64_t n, double *x, std::int64_t ldx, std::int64_t rows)
Definition
FixedOrderKernels.h:46
gpr::linalg::fixed::solveLeftTriangular
void solveLeftTriangular(const double *t, std::int64_t ldt, std::int64_t n, bool lower, double *b, std::int64_t ldb, std::int64_t cols)
Definition
FixedOrderKernels.h:67
gpr::linalg::fixed::subtractProductTransposed
void subtractProductTransposed(const double *a, std::int64_t lda, const double *bt, std::int64_t ldbt, double *c, std::int64_t ldc, std::int64_t m, std::int64_t n, std::int64_t k)
Definition
FixedOrderKernels.h:120
gpr::linalg::fixed::subtractProduct
void subtractProduct(const double *a, std::int64_t lda, bool transpose_a, const double *b, std::int64_t ldb, double *c, std::int64_t ldc, std::int64_t m, std::int64_t n, std::int64_t k)
Definition
FixedOrderKernels.h:96
gpr::linalg::fixed::choleskyLower
bool choleskyLower(double *a, std::int64_t lda, std::int64_t n)
Definition
FixedOrderKernels.h:23
gpr
linalg
FixedOrderKernels.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf