Skip to content

Commit

Permalink
Updates for Julia 1.0
Browse files Browse the repository at this point in the history
* Fixes bug (see #5) in hard_sphere which was not returning the right indices.
* Added more explicit description of the arguments to hard_sphere
* Updated benchmarks, README to match recent changes. Added .toml files
chrisvwx authored Aug 26, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 206af03 commit 536ebb2
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 48 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sudo: required
language: julia
julia:
- 0.7
- 1.0
- nightly
notifications:
email: false
164 changes: 164 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BenchmarkTools]]
deps = ["JSON", "Pkg", "Printf", "Statistics", "Test"]
git-tree-sha1 = "623941d5eb10e440eb12c97183f96f2f0191d0ca"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "0.4.0"

[[ColorTypes]]
deps = ["FixedPointNumbers", "Random", "Test"]
git-tree-sha1 = "0e3209ba7418aed732e5c3818076b4400ee36c08"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.7.4"

[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Pkg", "Printf", "Reexport", "Test"]
git-tree-sha1 = "26f24e97782dd19d52cf97073c316897ac4d0e30"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.9.3"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "277d3807440d9793421354b6680911fc95d91a84"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "1.0.1"

[[Conda]]
deps = ["Compat", "JSON", "VersionParsing"]
git-tree-sha1 = "a47f9a2c7b80095e6a935536795635522fe27f5d"
uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d"
version = "1.0.1"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[FixedPointNumbers]]
deps = ["Pkg", "Test"]
git-tree-sha1 = "31cbf24d537a217475b37274df05de09882b53f1"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.5.2"

[[InteractiveUtils]]
deps = ["LinearAlgebra", "Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JSON]]
deps = ["Dates", "Distributed", "Mmap", "Pkg", "Sockets", "Test", "Unicode"]
git-tree-sha1 = "fec8e4d433072731466d37ed0061b3ba7f70eeb9"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.19.0"

[[LaTeXStrings]]
deps = ["Compat"]
git-tree-sha1 = "7ab9b8788cfab2bdde22adf9004bda7ad9954b6c"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.0.2"

[[LibGit2]]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[MacroTools]]
deps = ["Compat"]
git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.4.4"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[PyCall]]
deps = ["Compat", "Conda", "MacroTools", "Statistics", "VersionParsing"]
git-tree-sha1 = "993d80a2cfd0fc4b2acc698370a4f9761b27cd9e"
uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
version = "1.18.2"

[[PyPlot]]
deps = ["Base64", "Colors", "Compat", "LaTeXStrings", "PyCall", "VersionParsing"]
git-tree-sha1 = "1cc673ec375f6fa0e3652e23ba435195f8175387"
uuid = "d330b81b-6aea-500a-939a-2ce795aea3ee"
version = "2.6.1"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[Reexport]]
deps = ["Pkg"]
git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "0.2.0"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[UUIDs]]
deps = ["Random"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[VersionParsing]]
deps = ["Compat"]
git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669"
uuid = "81def892-9a0e-5fdd-b105-ffc91e053289"
version = "1.1.2"
14 changes: 14 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "LLLplus"
uuid = "debe38fc-a976-11e8-3c3c-550d720deef8"
keywords = ["lattice reduction", "LLL", "Seysen", "closest vector problem"]
authors = ["Christian Peel <chris.peel@ieee.org>"]
version = "0.7.0"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# LLLplus

[![Build Status](https://travis-ci.org/christianpeel/LLLplus.jl.svg?branch=master)](https://travis-ci.org/christianpeel/LLLplus.jl)
[![LLLplus](http://pkg.julialang.org/badges/LLLplus_release.svg)](http://pkg.julialang.org/?pkg=LLLplus&ver=0.6)
[![LLLplus](http://pkg.julialang.org/badges/LLLplus_release.svg)](http://pkg.julialang.org/?pkg=LLLplus&ver=0.7)

Lattice reduction and related lattice tools are used in wireless
communication, cryptography, and mathematics. This package provides
the following tools: Lenstra-Lenstra-Lovacsz (LLL) lattice reduction,
Seysen lattice reduction, a sphere decoder, and VBLAST matrix
decomposition. This package was created as a way to explore the Julia
language, and is not intended to be a cannonical tool for lattice
reduction; use at your own risk! :-)
reduction; *use at your own risk!* :-)

[LLL](https://en.wikipedia.org/wiki/Lenstra%E2%80%93Lenstra%E2%80%93Lov%C3%A1sz_lattice_basis_reduction_algorithm) [1]
lattice reduction is a powerful tool in computer science that is used
Expand Down Expand Up @@ -57,11 +57,10 @@ M = 200;
println("Testing VBLAST on $(M)x$(M) chunk of same matrix...")
@time (W,P,B) = vblast(H[1:M,1:M]);

# Time LLL, Seysen decompositions of a 100x100 Int128 matrix with
# Time LLL, Seysen decompositions of a 100x100 Int64 matrix with
# rand entries distributed uniformly between -100:100
N = 100;
H = zeros(Int64, N,N);
rand!(-100:100, H);
H = rand(-100:100,N,N);
println("Testing LLL on $(N)x$(N) real matrix...")
@time (B,T,Q,R) = lll(H);
println("Testing Seysen on same $(N)x$(N) matrix...")
Expand All @@ -70,8 +69,8 @@ println("Testing Seysen on same $(N)x$(N) matrix...")

### Execution Time results

On this page we give a few performance results from tests run on
Travis-CI during normal CI tests:
On this page we give a few performance results obtained from the
following command in the top-level LLLplus directory:
`julia -e 'include("benchmark/perftest.jl")'`
In the tests we time execution of the lattice-reduction functions,
average the results over multiple random matrices, and show results as
Expand All @@ -90,14 +89,16 @@ Though the focus of the package is on floating-point,
all the modules can handle a variety of data types. In the next figure
we show execution time for several datatypes (Int32, Int64,
Int128, Float64, BitInt, and BigFloat) which are used to
generate 10 4x4 matrices, over which execution time for the lattice
generate 100 4x4 matrices, over which execution time for the lattice
reduction techniques is averaged. The vertical axis is a logarithmic
representation of execution time as in the previous
figure. ![Time vs data type](benchmark/perfVsDataTypeN16.png)

### Future

Possible improvements include:
* Change from "LLLplus" to "LLLtoy" or some such to emphasize
the nature of this package.
* Add Block-Korkin-Zolotarev lattice redution, with improvements
as in [4], and Brun lattice reduction
* The [SVP](http://www.latticechallenge.org/svp-challenge/) Challenge
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.7-alpha
julia 0.7
12 changes: 6 additions & 6 deletions benchmark/lrtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ for a=1:length(out[1][2])
times[k] = out[k][1][a];
end
plotfun(xval,times,pColor[pIdx],label=out[1][2][a]);
pIdx = pIdx==length(pColor)? 1: pIdx + 1;
pIdx = pIdx==length(pColor) ? 1 : pIdx + 1;
end

xlabel(xlab);
Expand Down Expand Up @@ -109,18 +109,17 @@ times = ones(Nalgs,Ns)*Inf;
hermitef = ones(Nalgs,Ns)*Inf;
orthf = ones(Nalgs,Ns)*Inf;
#algNames = cell(Nalgs)
algNames = Array{Any}(Nalgs)

data = Array{dataType}(N,N);
algNames = Array{Any,1}(undef,Nalgs)
data = Array{dataType,2}(undef,N,N);

for ix = 1:Ns
cnum = Inf;
while cnum>1e5 # With Ints need to check for singular matrices
while cnum > 1e5 # With Ints need to check for singular matrices
data = randf!(data);
if !(dataType<:BigInt || dataType<:BigFloat)
cnum = cond(data)
else
cnum = 0
cnum = 0.0
end
end

Expand Down Expand Up @@ -159,6 +158,7 @@ end
outtimes = zeros(Nalgs,1);
outHF = zeros(Nalgs,1);
outOF = zeros(Nalgs,1);
mean(x) = sum(x)/length(x)
for ax = 1:Nalgs
# stimes = sort(vec(times[ax,:]));
# outtimes[ax] = mean(stimes[1:floor(Ns*2/3)]);
Expand Down
Binary file modified benchmark/perfVsDataTypeN16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified benchmark/perfVsNfloat32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 5 additions & 12 deletions benchmark/perftest.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
if VERSION<=v"0.6.3"
include("../src/LLLplus.jl")
else
using Pkg
end

Pkg.add("PyPlot")
Pkg.add("BenchmarkTools")
Pkg.add("Docile")

using PyPlot
using BenchmarkTools
using LLLplus
using Printf
using Random
using LinearAlgebra

include("lrtest.jl")

lrtest(5,2.^[2],[100],[Int32,Int64,Int128,Float64,BigInt,BigFloat],"rand")
lrtest(5,2 .^[2],[100],[Int32,Int64,Int128,Float64,BigInt,BigFloat],"rand")
savefig("benchmark/perfVsDataTypeN16.png") # run from root directory

lrtest(5,2.^[0:5;],[1],[Float64],"randn")
lrtest(5,2 .^[0:5;],[1],[Float64],"randn")
savefig("benchmark/perfVsNfloat32.png") # run from root directory
41 changes: 25 additions & 16 deletions src/hard_sphere.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
# @doc """
# x=hard_sphere(y,H,Nc)
# Solve the problem argmin_x ||y-Hx||, where the elements of x are
# integers. The input vector y is of dimension N, with H of dimension N
# by M, and the returned vector x of dimension M and comes from the
# integers 0:Nc-1.
# X=hard_sphere(Y,H,Nc)
# The input may be a matrix Y of dimension N by Ns, in which case
# the problem is solved for each column of Y, with the solutions in
# the columns of X.
#x=hard_sphere(y,H,Nc)
# Solve the problem argmin_x ||y-Hx||. The input vector y is of
# length N, with H of dimension N by M, and the returned vector x of
# length M. If Nc is even the elements of x are integers from
# [0:Nc-1]*2-(Nc-1); odd Nc is not yet supported. For Nc=2, we're
# searching the 2PAM constellation of [-1,1], and for nInt=4 we're
# searching [-3,-1,1,3].
#X=hard_sphere(Y,H,Nc)
# The input may be a matrix Y of dimension N by Ns, in which case the
# problem is solved for each column of Y, with the solutions in the
# columns of X.
#
# Examples:
# X = hard_sphere([1 2]', [1 2; 3 4],2)
# X = hard_sphere(rand(0:20,2,15), [1 2; 3 4],2)
# """ ->
function hard_sphere(Y::Array{Td,2},H::Array{Td,2},Nc) where {Td}
function hard_sphere(Y::AbstractArray{Td,2},H::AbstractArray{Td,2},Nc::Integer) where {Td}
(N,M) = size(H);

if length(Nc)==1;
Nc = ones(M,1)*Nc;
Qc = ones(M)*Nc;
if iseven(Nc)
xoffset = Qc.-1
xmult = 2
else
@error("Odd Nc is not yet supported.")
# To find a failing case, remove @error above, and compare w full
# search. The fix is likely minor (once it is found).
xoffset = floor.(Qc/2)
xmult = 1
end
(Q,R) = qr(H);
(N,Ns) = size(Y);
Xh = zeros(Int,M,Ns);
for ns = 1:Ns
yp = (Q'*Y[:,ns] + R*ones(M,1).*(Nc.-1))/2;
xp = algII_smart(yp,R,Nc);
# Xh[:,ns] = xp*2 -(Nc-1);
Xh[:,ns] = xp
yp = (Q'*Y[:,ns] + R*ones(M,1).*xoffset)/xmult;
xp = algII_smart(yp,R,Qc);
Xh[:,ns] = xp*xmult - xoffset;
end

return Xh
Expand Down
2 changes: 1 addition & 1 deletion src/seysen.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function seysen(H::Array{Td,2}) where {Td}
# [B,T,B_dual,num_it] = seysen{Td}(H::Array{Td,2})
# [B,T,B_dual,num_it] = seysen(H::Array{Td,2}) where Td
#
# Do greedy Seysen lattice reduction on the matrix H (real or
# complex-valued), returning T a unimodular matrix that reduces H;
Expand Down
7 changes: 3 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ C = [-1,1];
Z = rand(1:2,N,Ns);
X = C[Z];
Y = H*X+NN;
@time Zt = hard_sphere(Y,H,2);
@time Zt = hard_sphere(Y,H,2);
Zh = Zt.+1;
errRate = sum(abs.(Z.-Zh))/Ns;
@time Xt = hard_sphere(Y,H,2);
@time Xt = hard_sphere(Y,H,2);
errRate = sum(abs.(X-Xt))/Ns;
println("Error Rate is $(errRate). It should be zero or very small.\n")

# --------------
Expand Down

0 comments on commit 536ebb2

Please sign in to comment.