Skip to content

Commit

Permalink
Changed the way an integer type is chosen for unimodular matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvwx committed Jul 14, 2019
1 parent 08b8a60 commit 26a2d3c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# LLLplus.jl

[![Build Status](https://travis-ci.org/christianpeel/LLLplus.jl.svg?branch=master)](https://travis-ci.org/christianpeel/LLLplus.jl)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://pkg.julialang.org/docs/LLLplus/)

LLLplus includes
[Lenstra-Lenstra-Lovász](https://en.wikipedia.org/wiki/Lenstra%E2%80%93Lenstra%E2%80%93Lov%C3%A1sz_lattice_basis_reduction_algorithm)
Expand Down
8 changes: 8 additions & 0 deletions benchmark/perftest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ using Quadmath

include("lrtest.jl")

# getIntType is used to indicate what type we want the unimodular integer
# matrix to have. We need to add methods of getIntType to handle the
# DoubleFloats and Quadmath, since they are external packages that LLLplus
# doesn't know about. So yes, we do a bit of type piracy.
import LLLplus.getIntType
getIntType(Td::Type{Tr}) where {Tr<:Float128} = Int128
getIntType(Td::Type{Tr}) where {Tr<:Double64} = Int128

lrtest(40,2 .^[7],[100],[Int32,Int64,Int128,Float32,Float64,Float128,Double64,BigInt,BigFloat],"rand")
savefig("perfVsDataType.png")

Expand Down
53 changes: 23 additions & 30 deletions src/lll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,38 +138,31 @@ end
getIntType(Td)
Return an integer type that matches Td. I.e. BigInt for Td=BigFloat, Int64
for Td=Float64. Should replace this with multiple functions; the
following gives a hint, but it's not correct:
getIntType(Td::Complex{Tr}) = Complex{getIntType(Tr)}
getIntType(Td) where {Td<:Integer} = Td
getIntType(<:Float64) = Int64
getIntType(<:Float32) = Int32
getIntType(<:Float16) = Int16
getIntType(<:BigFloat) = BigInt
this is better:
getIntType(Td::Type{Tr}) where {Tr<:Float128} = Int128
for Td=Float64.
It's possible that the integer type could be picked on a per-matrix
basis depending on the values in the matrix and the decomposition
(i.e. [`lll`](@ref)) that is to be done. This is not done below.
# Examples
```julia-repl
julia> Pkg.add("DoubleFloats")
julia> using DoubleFloats
julia> using LLLplus
julia> import LLLplus.getIntType # yes, it's type piracy!
julia> x = randn(3,3); xd = Double64(x); lll(xd)
ERROR: MethodError: no method matching getIntType(::Type{DoubleFloat{Float64}})
...
julia> getIntType(Td::Type{Tr}) where {Tr<:Double64} = Int128
julia> B,T =lll(xd); # succeeds
```
"""
function getIntType(Td)
Tr = real(Td)
if Tr<:BigInt || Tr<:BigFloat
Ti = BigInt
elseif Tr==Float32 || Tr==Int32
Ti=Int32
elseif Tr==Int16
Ti=Int16
elseif Tr==Int8
Ti=Int8
else
Ti=Int
end
if Td<:Complex
Ti = Complex{Ti}
end
return Ti
end
getIntType(Td::Type{Tr}) where {Tr<:Integer} = Tr
getIntType(Td::Type{Tr}) where {Tr<:Float64} = Int64
getIntType(Td::Type{Tr}) where {Tr<:Float32} = Int32
getIntType(Td::Type{Tr}) where {Tr<:Float16} = Int16
getIntType(Td::Type{Tr}) where {Tr<:BigFloat} = BigInt
getIntType(Td::Type{Complex{Tr}}) where Tr = Complex{getIntType(Tr)}


"""
B,T,Q,R = sizereduction(H)
Expand Down

0 comments on commit 26a2d3c

Please sign in to comment.