Skip to content

Commit 996de98

Browse files
committed
update formatting rules
- adjust continuation indentation and bracket alignment - apply formatting fixes across the repository
1 parent a90b153 commit 996de98

213 files changed

Lines changed: 4361 additions & 6967 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.clang-format‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ BasedOnStyle: Microsoft
44

55
# Indentation
66
IndentWidth: 2 # 2 spaces per indent
7+
ContinuationIndentWidth: 2
78
AccessModifierOffset: -2
89
IndentAccessModifiers: false # Align access modifiers to braces
910
NamespaceIndentation: All # Indent namspace contents
@@ -12,7 +13,6 @@ ConstructorInitializerIndentWidth: 2
1213
# Comments which match this regex will be unformatted (and therefore can be longer or have more whitespace than other comments)
1314
CommentPragmas: '^\*\*'
1415

15-
1616
# Alignment
1717
AlignConsecutiveAssignments:
1818
Enabled: true
@@ -37,6 +37,7 @@ AlignConsecutiveMacros:
3737
AcrossComments: true
3838

3939
# Newlines
40+
AlignAfterOpenBracket: BlockIndent # this will need to be replaced w/ clang-format 22
4041
ColumnLimit: 0
4142
BreakBeforeBraces: Allman # Braces on their own lines
4243
SeparateDefinitionBlocks: Always # Separate definitions (functions etc.) with an empty line

‎GridKit/AutomaticDifferentiation/DependencyTracking/VariableOperators.hpp‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,21 @@ namespace std
378378
return res; \
379379
}
380380

381-
#define IMPL_FUN_2(FUN, DER1, DER2) \
382-
inline GridKit::DependencyTracking::Variable FUN(const GridKit::DependencyTracking::Variable& x, \
383-
const GridKit::DependencyTracking::Variable& y) \
384-
{ \
385-
double val = FUN(x(), y()); \
386-
double der1 = DER1(x(), y()); \
387-
double der2 = DER2(x(), y()); \
388-
GridKit::DependencyTracking::Variable res1(x); /* copy derivatives of x*/ \
389-
GridKit::DependencyTracking::Variable res2(y); /* copy derivatives of y*/ \
390-
res1.setValue(val); /* set function value f(x, y) */ \
391-
res2.setValue(val); /* set function value f(x, y) */ \
392-
res1.scaleDependencies(der1); /* compute derivatives of f(x, y) with respect to x */ \
393-
res2.scaleDependencies(der2); /* compute derivatives of f(x, y) with respect to y */ \
394-
GridKit::DependencyTracking::Variable res(std::move(res1)); /* relocate derivatives w.r.t. x into return */ \
395-
res.addDependencies(res2); /* add derivatives with respect to y to return */ \
396-
return res; \
381+
#define IMPL_FUN_2(FUN, DER1, DER2) \
382+
inline GridKit::DependencyTracking::Variable FUN(const GridKit::DependencyTracking::Variable& x, const GridKit::DependencyTracking::Variable& y) \
383+
{ \
384+
double val = FUN(x(), y()); \
385+
double der1 = DER1(x(), y()); \
386+
double der2 = DER2(x(), y()); \
387+
GridKit::DependencyTracking::Variable res1(x); /* copy derivatives of x*/ \
388+
GridKit::DependencyTracking::Variable res2(y); /* copy derivatives of y*/ \
389+
res1.setValue(val); /* set function value f(x, y) */ \
390+
res2.setValue(val); /* set function value f(x, y) */ \
391+
res1.scaleDependencies(der1); /* compute derivatives of f(x, y) with respect to x */ \
392+
res2.scaleDependencies(der2); /* compute derivatives of f(x, y) with respect to y */ \
393+
GridKit::DependencyTracking::Variable res(std::move(res1)); /* relocate derivatives w.r.t. x into return */ \
394+
res.addDependencies(res2); /* add derivatives with respect to y to return */ \
395+
return res; \
397396
}
398397

399398
IMPL_FUN_1(sin, GridKit::DependencyTracking::sin_derivative)

‎GridKit/AutomaticDifferentiation/Enzyme/D2LDx2.hpp‎

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,14 @@ namespace GridKit
4040
* @param[out] nnz - Number of nonzeros
4141
*/
4242
template <typename ScalarT, typename IdxT, typename RealT>
43-
static void eval(const ModelT* model,
44-
const size_t n_var,
45-
const IdxT* variable_indices,
46-
const ScalarT* x,
47-
const RealT sigma,
48-
const RealT* lambda,
49-
IdxT* rows,
50-
IdxT* cols,
51-
ScalarT* vals,
52-
IdxT& nnz)
43+
static void eval(const ModelT* model, const size_t n_var, const IdxT* variable_indices, const ScalarT* x, const RealT sigma, const RealT* lambda, IdxT* rows, IdxT* cols, ScalarT* vals, IdxT& nnz)
5344
{
5445
std::array<ScalarT, ObjectiveT::NUM_INPUTS> gradient{};
5546
for (size_t var_i = 0; var_i < n_var; ++var_i)
5647
{
5748
// Sparse storage. @see LowerSparseStorage.hpp
58-
ScalarT* seed = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT, IdxT>,
59-
(void*) ident_store<ScalarT, IdxT>,
60-
var_i);
61-
ScalarT* dgradient = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT, IdxT>,
62-
(void*) sparse_store<ScalarT, IdxT>,
63-
var_i,
49+
ScalarT* seed = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT, IdxT>, (void*) ident_store<ScalarT, IdxT>, var_i);
50+
ScalarT* dgradient = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT, IdxT>, (void*) sparse_store<ScalarT, IdxT>, var_i,
6451
1.0, // value scaling
6552
variable_indices,
6653
variable_indices,
@@ -69,19 +56,7 @@ namespace GridKit
6956
vals,
7057
&nnz);
7158

72-
__enzyme_fwddiff<void>((void*) lagrangianGradient<ScalarT, RealT>,
73-
enzyme_const,
74-
model,
75-
enzyme_dup,
76-
x,
77-
seed,
78-
enzyme_dupnoneed,
79-
gradient.data(),
80-
dgradient,
81-
enzyme_const,
82-
sigma,
83-
enzyme_const,
84-
lambda);
59+
__enzyme_fwddiff<void>((void*) lagrangianGradient<ScalarT, RealT>, enzyme_const, model, enzyme_dup, x, seed, enzyme_dupnoneed, gradient.data(), dgradient, enzyme_const, sigma, enzyme_const, lambda);
8560
}
8661
}
8762

@@ -90,10 +65,7 @@ namespace GridKit
9065
using ConstraintsT = ModelWrapper<ModelT, MemberFunctions::Constraints>;
9166

9267
template <typename ScalarT, typename RealT>
93-
[[gnu::always_inline]] inline static ScalarT lagrangian(const ModelT* model,
94-
const ScalarT* x,
95-
const RealT sigma,
96-
const RealT* lambda)
68+
[[gnu::always_inline]] inline static ScalarT lagrangian(const ModelT* model, const ScalarT* x, const RealT sigma, const RealT* lambda)
9769
{
9870
std::array<ScalarT, ConstraintsT::NUM_OUTPUTS> g{};
9971
ConstraintsT::eval(model, x, g.data());
@@ -108,22 +80,9 @@ namespace GridKit
10880

10981
/// Add the Lagrangian gradient to `gradient`, whose tangent alone is used
11082
template <typename ScalarT, typename RealT>
111-
[[gnu::always_inline]] inline static void lagrangianGradient(const ModelT* model,
112-
const ScalarT* x,
113-
ScalarT* gradient,
114-
const RealT sigma,
115-
const RealT* lambda)
83+
[[gnu::always_inline]] inline static void lagrangianGradient(const ModelT* model, const ScalarT* x, ScalarT* gradient, const RealT sigma, const RealT* lambda)
11684
{
117-
__enzyme_autodiff<void>((void*) lagrangian<ScalarT, RealT>,
118-
enzyme_const,
119-
model,
120-
enzyme_dup,
121-
x,
122-
gradient,
123-
enzyme_const,
124-
sigma,
125-
enzyme_const,
126-
lambda);
85+
__enzyme_autodiff<void>((void*) lagrangian<ScalarT, RealT>, enzyme_const, model, enzyme_dup, x, gradient, enzyme_const, sigma, enzyme_const, lambda);
12786
}
12887
};
12988
} // namespace Sparse

‎GridKit/AutomaticDifferentiation/Enzyme/DfDwb.hpp‎

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,15 @@ namespace GridKit
4444
* @param[out] vals - Values
4545
* @param[out] nnz - Number of nonzeros
4646
*/
47-
static void eval(ModelT* model,
48-
const size_t n_res,
49-
const size_t n_var,
50-
const IdxT* res_indices,
51-
const IdxT* var_indices,
52-
const ScalarT* y,
53-
const ScalarT* yp,
54-
const ScalarT* wb,
55-
IdxT* rows,
56-
IdxT* cols,
57-
RealT* vals,
58-
IdxT& nnz)
47+
static void eval(ModelT* model, const size_t n_res, const size_t n_var, const IdxT* res_indices, const IdxT* var_indices, const ScalarT* y, const ScalarT* yp, const ScalarT* wb, IdxT* rows, IdxT* cols, RealT* vals, IdxT& nnz)
5948
{
6049
if (n_res > 0 && n_var > 0)
6150
{
6251
for (size_t var_i = 0; var_i < n_var; ++var_i)
6352
{
6453
// Sparse storage. @see LowerSparseStorage.hpp
65-
ScalarT* output = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT, IdxT>,
66-
(void*) ident_store<ScalarT, IdxT>,
67-
var_i);
68-
ScalarT* d_output = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT, IdxT>,
69-
(void*) sparse_store<ScalarT, IdxT>,
70-
var_i,
54+
ScalarT* output = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT, IdxT>, (void*) ident_store<ScalarT, IdxT>, var_i);
55+
ScalarT* d_output = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT, IdxT>, (void*) sparse_store<ScalarT, IdxT>, var_i,
7156
1.0, // value scaling
7257
res_indices,
7358
var_indices,
@@ -78,15 +63,7 @@ namespace GridKit
7863

7964
// Core automatic differentiation intrinsic that will be replaced by a derivative
8065
// The dummy primal pointer is safe only while residuals never read back their output
81-
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
82-
enzyme_const,
83-
model,
84-
enzyme_const,
85-
y,
86-
enzyme_const,
87-
yp,
88-
enzyme_dup,
89-
wb,
66+
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval, enzyme_const, model, enzyme_const, y, enzyme_const, yp, enzyme_dup, wb,
9067
output, // Seed: column var_i of the identity
9168
enzyme_dupnoneed,
9269
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
@@ -110,31 +87,15 @@ namespace GridKit
11087
* @param[out] vals - Values
11188
* @param[out] nnz - Number of nonzeros
11289
*/
113-
static void eval(ModelT* model,
114-
const size_t n_res,
115-
const size_t n_var,
116-
const IdxT* res_indices,
117-
const IdxT* var_indices,
118-
const ScalarT* y,
119-
const ScalarT* yp,
120-
const ScalarT* wb,
121-
const ScalarT* ws,
122-
IdxT* rows,
123-
IdxT* cols,
124-
RealT* vals,
125-
IdxT& nnz)
90+
static void eval(ModelT* model, const size_t n_res, const size_t n_var, const IdxT* res_indices, const IdxT* var_indices, const ScalarT* y, const ScalarT* yp, const ScalarT* wb, const ScalarT* ws, IdxT* rows, IdxT* cols, RealT* vals, IdxT& nnz)
12691
{
12792
if (n_res > 0 && n_var > 0)
12893
{
12994
for (size_t var_i = 0; var_i < n_var; ++var_i)
13095
{
13196
// Sparse storage. @see LowerSparseStorage.hpp
132-
ScalarT* output = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT, IdxT>,
133-
(void*) ident_store<ScalarT, IdxT>,
134-
var_i);
135-
ScalarT* d_output = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT, IdxT>,
136-
(void*) sparse_store<ScalarT, IdxT>,
137-
var_i,
97+
ScalarT* output = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT, IdxT>, (void*) ident_store<ScalarT, IdxT>, var_i);
98+
ScalarT* d_output = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT, IdxT>, (void*) sparse_store<ScalarT, IdxT>, var_i,
13899
1.0, // value scaling
139100
res_indices,
140101
var_indices,
@@ -145,15 +106,7 @@ namespace GridKit
145106

146107
// Core automatic differentiation intrinsic that will be replaced by a derivative
147108
// The dummy primal pointer is safe only while residuals never read back their output
148-
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
149-
enzyme_const,
150-
model,
151-
enzyme_const,
152-
y,
153-
enzyme_const,
154-
yp,
155-
enzyme_dup,
156-
wb,
109+
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval, enzyme_const, model, enzyme_const, y, enzyme_const, yp, enzyme_dup, wb,
157110
output, // Seed: column var_i of the identity
158111
enzyme_const,
159112
ws,

0 commit comments

Comments
 (0)