Skip to content

Commit

Permalink
Apply clang-tidy suggestions to HMV::Derive
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi authored and vgvassilev committed Oct 5, 2024
1 parent dfdd2dc commit b112290
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/Differentiator/HessianModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ DerivativeAndOverload HessianModeVisitor::Derive() {
DiffParams args{};
IndexIntervalTable indexIntervalTable{};
if (m_DiffReq.Args)
for (auto dParam : m_DiffReq.DVI) {
for (const auto& dParam : m_DiffReq.DVI) {
args.push_back(dParam.param);
indexIntervalTable.push_back(dParam.paramIndexInterval);
}
Expand All @@ -117,8 +117,8 @@ DerivativeAndOverload HessianModeVisitor::Derive() {
if (args.size() != FD->getNumParams() ||
!std::equal(m_DiffReq->param_begin(), m_DiffReq->param_end(),
args.begin())) {
for (auto arg : args) {
auto it =
for (const ValueDecl* arg : args) {
const auto* it =
std::find(m_DiffReq->param_begin(), m_DiffReq->param_end(), arg);
auto idx = std::distance(m_DiffReq->param_begin(), it);
hessianFuncName += ('_' + std::to_string(idx));
Expand Down Expand Up @@ -152,21 +152,21 @@ DerivativeAndOverload HessianModeVisitor::Derive() {
// iteration, storing each generated second derivative function
// (corresponds to columns of Hessian matrix) in a vector for private method
// merge.
for (auto PVD : FD->parameters()) {
auto it = std::find(std::begin(args), std::end(args), PVD);
for (const ParmVarDecl* PVD : FD->parameters()) {
auto* it = std::find(std::begin(args), std::end(args), PVD);
if (it != args.end()) {
// Using the properties of a vector to find the index of the requested
// arg
auto argIndex = it - args.begin();
if (isArrayOrPointerType(PVD->getType())) {
if (indexIntervalTable.size() == 0 ||
if (indexIntervalTable.empty() ||
indexIntervalTable[argIndex].size() == 0) {
std::string suggestedArgsStr{};
if (auto SL = dyn_cast<StringLiteral>(
if (const auto* SL = dyn_cast<StringLiteral>(
m_DiffReq.Args->IgnoreParenImpCasts())) {
llvm::StringRef str = SL->getString().trim();
llvm::StringRef name{};
do {
while (!str.empty()) {
std::tie(name, str) = str.split(',');
if (name.trim().str() == PVD->getNameAsString()) {
suggestedArgsStr += (suggestedArgsStr.empty() ? "" : ", ") +
Expand All @@ -177,7 +177,7 @@ DerivativeAndOverload HessianModeVisitor::Derive() {
suggestedArgsStr +=
(suggestedArgsStr.empty() ? "" : ", ") + name.trim().str();
}
} while (!str.empty());
}
} else {
suggestedArgsStr = PVD->getNameAsString() + "[0:<last index of b>]";
}
Expand All @@ -202,7 +202,7 @@ DerivativeAndOverload HessianModeVisitor::Derive() {
i < indexIntervalTable[argIndex].Finish; i++) {
auto independentArgString =
PVD->getNameAsString() + "[" + std::to_string(i) + "]";
auto ForwardModeIASL =
const StringLiteral* ForwardModeIASL =
CreateStringLiteral(m_Context, independentArgString);
FunctionDecl* DFD = nullptr;
if (m_DiffReq.Mode == DiffMode::hessian_diagonal)
Expand All @@ -220,7 +220,7 @@ DerivativeAndOverload HessianModeVisitor::Derive() {
TotalIndependentArgsSize++;
// Derive the function w.r.t. to the current arg in forward mode and
// then in reverse mode w.r.t to all requested args
auto ForwardModeIASL =
const StringLiteral* ForwardModeIASL =
CreateStringLiteral(m_Context, PVD->getNameAsString());
FunctionDecl* DFD = nullptr;
if (m_DiffReq.Mode == DiffMode::hessian_diagonal)
Expand Down

0 comments on commit b112290

Please sign in to comment.