Skip to content

Commit 6112a12

Browse files
committed
reduce allocs
1 parent 15b96de commit 6112a12

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/AlphaStableDistributions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function Distributions.fit(d::Type{<:AlphaSubGaussian}, x::AbstractVector{T}, m:
277277
α = d1.α; scale=d1.scale
278278
cov = zeros(T, m+1, m+1)
279279
xlen = length(x)
280-
c = ((sum(abs.(x).^p)/xlen)^(1/p))/scale
280+
c = ((sum(x->abs(x)^p, x)/xlen)^(1/p))/scale
281281
for i in 1:m
282282
tempxlen = xlen-mod(xlen, i)
283283
xtemp = reshape(x[1:end-mod(xlen, i)], i, tempxlen÷i)
@@ -286,7 +286,7 @@ function Distributions.fit(d::Type{<:AlphaSubGaussian}, x::AbstractVector{T}, m:
286286
tempxlen = size(xtemp, 1)*size(xtemp, 2)
287287
end
288288
xtemp = reshape(xtemp', 2, tempxlen÷2)
289-
r = (2/(c^p))*(scale^(2-p))*(xtemp[1, :]'*((sign.(xtemp[2, :]).*(abs.(xtemp[2, :]).^(p-1)))))/(tempxlen/2)
289+
@views r = (2/(c^p))*(scale^(2-p))*(xtemp[1, :]'*((sign.(xtemp[2, :]).*(abs.(xtemp[2, :]).^(p-1)))))/(tempxlen/2)
290290
cov[diagind(cov, i)] .+= r
291291
end
292292
cov = (cov+cov')+2*(scale^2)*I(m+1)

0 commit comments

Comments
 (0)