Skip to content

Commit

Permalink
Optimizing and formatting the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankwswang committed Dec 28, 2024
1 parent d527a48 commit c6d0b4a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Integrals/Interface.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const OneTwoTpl{T} = Union{Tuple{T}, NTuple{2, T}}

const FrameworkOrbSet{T, D} = AbstractVector{<:FrameworkOrb{T, D}}

const OrbCoreIdxDict{T} =
Dict{Tuple{FieldMarker{:PrimitiveOrbCore, 1}, AbtVecOfAbtArr{T}}, Int}

Expand Down Expand Up @@ -40,6 +42,8 @@ struct BasisIndexer{T}
renormalize::Bool
end

const BasisIdxerVec{T} = AbstractVector{BasisIndexer{T}}

abstract type IntegralIndexer{T, N} <: QueryBox{T} end

struct OneBodyIntegralIndexer{T<:Number} <: IntegralIndexer{T, 1}
Expand Down Expand Up @@ -146,14 +150,10 @@ genPrimOneBodyIntVal(op, (oData, oData), idx)
function computeOneBodyInt(op::DirectOperator,
(oData1, oData2)::NTuple{2, OrbCoreInfoVec{T, D}},
(dIdx1, dIdx2)::NTuple{2, Int}) where {T, D}
pairs1 = Memory{Pair{Tuple{Int}, Tuple{T}}}([])

pairs2 = map(Iterators.product( eachindex(oData1), eachindex(oData2) )) do (i, j)
map(Iterators.product( eachindex(oData1), eachindex(oData2) )) do (i, j)
ijValPair = genPrimOneBodyIntVal(op, (oData1, oData2), (i, j))
(i+dIdx1, j+dIdx2) => ijValPair
end |> vec

pairs1, pairs2
end

# function computeOneBodyInt(op::DirectOperator,
Expand Down Expand Up @@ -244,8 +244,6 @@ function cacheIntComponents!(intCache::IntegralCache{T, D},
BasisIndexer(pairs, isRenormalized(orb)), maxIdx
end

const FrameworkOrbSet{T, D} = AbstractVector{<:FrameworkOrb{T, D}}

function cacheIntComponents!(intCache::IntegralCache{T, D},
paramCache::DimSpanDataCacheBox{T},
orbs::FrameworkOrbSet{T, D}) where {T, D}
Expand Down Expand Up @@ -281,14 +279,22 @@ initializeOverlapCache!(paramCache::DimSpanDataCacheBox{T},
initializeIntCache!(Val(1), Identity(), paramCache, orbs)

function updateIntCacheCore!(op::DirectOperator, idxer::OneBodyIntegralIndexer{T},
basis::NonEmptyTuple{OrbCoreInfoVec{T, D}, N},
offset::NonEmptyTuple{Int, N}) where {T, N, D}
basis::Tuple{OrbCoreInfoVec{T, D}},
offset::Tuple{Int}) where {T, D}
pairs1, pairs2 = computeOneBodyInt(op, basis, offset)
foreach(p->setIntegralIndexer!(idxer, p), pairs1)
foreach(p->setIntegralIndexer!(idxer, p), pairs2)
idxer
end

function updateIntCacheCore!(op::DirectOperator, idxer::OneBodyIntegralIndexer{T},
basis::NTuple{2, OrbCoreInfoVec{T, D}},
offset::NTuple{2, Int}) where {T, D}
pairs2 = computeOneBodyInt(op, basis, offset)
foreach(p->setIntegralIndexer!(idxer, p), pairs2)
idxer
end

function updateIntCache!(cache::IntegralCache, startIdx::Int)
op = cache.operator
basis = cache.basis.list
Expand Down Expand Up @@ -516,8 +522,6 @@ function buildOneBodyEleTuple(intConfig::Tuple{ OverlapCache{T, D},
buildOneBodyEleTuple(intConfig, intConfig)
end

const BasisIdxerVec{T} = AbstractVector{BasisIndexer{T}}

function buildOneBodyTensor(intConfig::Tuple{IntegralCache{T, D, 1}, BasisIdxerVec{T}},
nlzConfig::Tuple{ OverlapCache{T, D}, BasisIdxerVec{T}}
) where {T, D}
Expand Down

0 comments on commit c6d0b4a

Please sign in to comment.