2017-06-25 09:28:44 +02:00
|
|
|
using IntervalArithmetic
|
|
|
|
|
2017-07-26 12:58:39 +02:00
|
|
|
IntervalArithmetic.setrounding(Interval, :tight)
|
2017-10-27 18:25:13 +02:00
|
|
|
IntervalArithmetic.setformat(sigfigs=12)
|
2017-06-25 09:28:44 +02:00
|
|
|
|
2019-03-15 08:13:38 +01:00
|
|
|
function fma_SOS_thr!(result::AbstractVector{T}, pm::AbstractMatrix{<:Integer},
|
|
|
|
Q::AbstractMatrix{T}, acc_matrix=zeros(T, size(pm)...)) where T
|
|
|
|
|
|
|
|
s1, s2 = size(pm)
|
|
|
|
|
|
|
|
@inbounds for k in 1:s2
|
|
|
|
let k=k, s1=s1, s2=s2, Q=Q, acc_matrix=acc_matrix
|
|
|
|
Threads.@threads for j in 1:s2
|
|
|
|
for i in 1:s1
|
|
|
|
@inbounds acc_matrix[i,j] = muladd(Q[i, k], Q[j, k], acc_matrix[i,j])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-01 23:45:49 +01:00
|
|
|
end
|
2019-03-15 08:13:38 +01:00
|
|
|
|
|
|
|
@inbounds for j in 1:s2
|
|
|
|
for i in 1:s1
|
|
|
|
result[pm[i,j]] += acc_matrix[i,j]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-01 23:45:49 +01:00
|
|
|
return result
|
2017-03-13 14:49:55 +01:00
|
|
|
end
|
|
|
|
|
2019-03-15 08:13:38 +01:00
|
|
|
function compute_SOS(pm::AbstractMatrix{<:Integer}, Q::AbstractMatrix)
|
|
|
|
result = zeros(eltype(Q), maximum(pm));
|
|
|
|
return fma_SOS_thr!(result, pm, Q)
|
|
|
|
end
|
|
|
|
|
|
|
|
function compute_SOS(RG::GroupRing, Q::AbstractMatrix{<:Real})
|
2018-08-14 19:18:36 +02:00
|
|
|
result = compute_SOS(RG.pm, Q)
|
2018-08-15 19:08:40 +02:00
|
|
|
return GroupRingElem(result, RG)
|
2017-10-27 18:30:59 +02:00
|
|
|
end
|
2017-03-15 17:51:13 +01:00
|
|
|
|
2019-03-15 08:13:38 +01:00
|
|
|
function compute_SOS_square(RG::GroupRing, Q::AbstractMatrix{<:Real})
|
|
|
|
result = zeros(eltype(Q), maximum(RG.pm));
|
2019-04-12 23:18:48 +02:00
|
|
|
|
2019-03-15 08:13:38 +01:00
|
|
|
for i in 1:size(Q,2)
|
|
|
|
GroupRings.fmac!(result, view(Q,:,i), view(Q,:,i), RG.pm)
|
|
|
|
end
|
2019-04-12 23:18:48 +02:00
|
|
|
|
2019-03-15 08:13:38 +01:00
|
|
|
return GroupRingElem(result, RG)
|
|
|
|
end
|
|
|
|
|
2019-03-14 14:25:32 +01:00
|
|
|
function augIdproj(Q::AbstractMatrix{T}) where {T<:Real}
|
2019-01-08 04:59:41 +01:00
|
|
|
result = zeros(size(Q))
|
2018-01-01 14:06:33 +01:00
|
|
|
l = size(Q, 2)
|
|
|
|
Threads.@threads for j in 1:l
|
|
|
|
col = sum(view(Q, :,j))/l
|
2018-08-14 18:18:25 +02:00
|
|
|
for i in 1:size(Q, 1)
|
2019-01-08 04:59:41 +01:00
|
|
|
result[i,j] = Q[i,j] - col
|
2018-01-01 14:06:33 +01:00
|
|
|
end
|
|
|
|
end
|
2018-09-05 10:41:11 +02:00
|
|
|
return result
|
2017-03-14 23:35:52 +01:00
|
|
|
end
|
2017-03-13 14:49:55 +01:00
|
|
|
|
2019-01-11 06:37:24 +01:00
|
|
|
function augIdproj(::Type{Interval}, Q::AbstractMatrix{T}) where {T<:Real}
|
2019-01-08 04:59:41 +01:00
|
|
|
result = zeros(Interval{T}, size(Q))
|
|
|
|
l = size(Q, 2)
|
|
|
|
Threads.@threads for j in 1:l
|
|
|
|
col = sum(view(Q, :,j))/l
|
|
|
|
for i in 1:size(Q, 1)
|
|
|
|
result[i,j] = @interval(Q[i,j] - col)
|
|
|
|
end
|
2017-04-17 15:22:33 +02:00
|
|
|
end
|
2019-01-08 04:59:41 +01:00
|
|
|
check = all([zero(T) in sum(view(result, :, i)) for i in 1:size(result, 2)])
|
|
|
|
return result, check
|
2017-03-13 14:49:55 +01:00
|
|
|
end
|