Skip to content

Commit e3d2a1b

Browse files
GiggleLiuRoger-luo
andauthored
rm luxurysparse dep (#23)
* rm luxurysparse dep * fix tests * fix tests, update project.toml * Update Project.toml Co-authored-by: Rogerluo <[email protected]>
1 parent db6a306 commit e3d2a1b

8 files changed

+36
-42
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
name = "BitBasis"
22
uuid = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf"
3-
version = "0.6.2"
3+
version = "0.7.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
7-
LuxurySparse = "d05aeea4-b7d4-55ac-b691-9e7fabb07ba2"
87
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
98

109
[compat]
11-
LuxurySparse = "0.5, 0.6"
1210
StaticArrays = "0.12"
1311
julia = "1"
1412

src/bit_str.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ julia> bit_literal(1, 0, 1, 0, 1, 1)
313313
110101 ₍₂₎
314314
```
315315
"""
316-
bit_literal(xs...) = bit_literal(xs)
316+
bit_literal(xs::Int...) = bit_literal(xs)
317317
function bit_literal(xs::NTuple{N,T}) where {N,T<:Integer}
318318
val = T(0)
319319
for k in 1:N

src/operations.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export bitarray, basis, packbits, bfloat, bfloat_r, bint, bint_r, flip
22
export anyone, allone, bmask, baddrs, readbit, setbit, controller
33
export swapbits, ismatch, neg, breflect, btruncate
4+
export rand_bitstr64
45

56
"""
67
bitarray(v::Vector, [nbits::Int]) -> BitArray
@@ -335,3 +336,10 @@ function controller(cbits::IntIterator{Int}, cvals::IntIterator{Int})
335336
mapreduce(xy -> (xy[2] == 1 ? 1 << (xy[1] - 1) : 0), |, zip(cbits, cvals))
336337
return b -> ismatch(b, do_mask, target)
337338
end
339+
340+
function rand_bitstr64(nbit::Int)
341+
T = BitStr64{nbit}
342+
rand(typemin(T):typemax(T))
343+
end
344+
Base.rand(::Type{T}) where T<:BitStr = rand(typemin(T):typemax(T))
345+

src/reorder.jl

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export ReorderedBasis, reorder, invorder
22

3-
using LuxurySparse, LinearAlgebra
3+
using LinearAlgebra
44

55
"""
66
ReorderedBasis{N, T}
@@ -78,25 +78,6 @@ function unsafe_reorder(A::AbstractMatrix, orders::NTuple{N,<:Integer}) where {N
7878
return A[od, od]
7979
end
8080

81-
unsafe_reorder(A::IMatrix, orders::NTuple{N,<:Integer}) where {N} = A
82-
83-
function unsafe_reorder(A::PermMatrix, orders::NTuple{N,<:Integer}) where {N}
84-
od = Vector{Int}(undef, 1 << length(orders))
85-
for (i, b) in enumerate(ReorderedBasis(orders))
86-
@inbounds od[i] = 1 + b
87-
end
88-
89-
perm = similar(A.perm)
90-
vals = similar(A.vals)
91-
92-
@simd for i in 1:length(perm)
93-
@inbounds perm[od[i]] = od[A.perm[i]]
94-
@inbounds vals[od[i]] = A.vals[i]
95-
end
96-
97-
return PermMatrix(perm, vals)
98-
end
99-
10081
function unsafe_reorder(A::Diagonal, orders::NTuple{N,<:Integer}) where {N}
10182
diag = similar(A.diag)
10283
for (i, b) in enumerate(ReorderedBasis(orders))

test/iterate_control.jl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Test, BitBasis, LuxurySparse
1+
using Test, BitBasis
22

33
function swaprows!(v::AbstractVector, i::Int, j::Int)
44
temp = v[i]
@@ -7,6 +7,14 @@ function swaprows!(v::AbstractVector, i::Int, j::Int)
77
v
88
end
99

10+
function eye(b::Int)
11+
res = zeros(b, b)
12+
for i=1:b
13+
res[i,i] = 1
14+
end
15+
res
16+
end
17+
1018
mulrow!(v::AbstractVector, i::Int, f) = (v[i] *= f; v)
1119

1220
@testset "test group_shift! and lmove" begin
@@ -43,15 +51,15 @@ end
4351
rrr = copy(v)
4452
controldo(x -> mulrow!(rrr, x + 1, -1.0), it4)
4553
M =
46-
kron(P1, IMatrix(2), P1, Z) +
47-
kron(P0, IMatrix(2), P0, IMatrix(2)) +
48-
kron(P1, IMatrix(2), P0, IMatrix(2)) +
49-
kron(P0, IMatrix(2), P1, IMatrix(2))
54+
kron(P1, eye(2), P1, Z) +
55+
kron(P0, eye(2), P0, eye(2)) +
56+
kron(P1, eye(2), P0, eye(2)) +
57+
kron(P0, eye(2), P1, eye(2))
5058
@test rrr M * v
5159

5260
it = itercontrol(8, [3], [1])
5361
V = randn(ComplexF64, 1 << 8)
54-
res = kron(IMatrix(1 << 5), ComplexF64[0 1; 1 0], IMatrix(1 << 2)) * V
62+
res = kron(eye(1 << 5), ComplexF64[0 1; 1 0], eye(1 << 2)) * V
5563
rrr = copy(V)
5664
controldo(x -> swaprows!(rrr, x + 1, x - 3), it)
5765
@test rrr res
@@ -60,10 +68,10 @@ end
6068
controldo(x -> mulrow!(rrr, x + 1, -1), itercontrol(8, [3, 7, 6], [1, 1, 1]))
6169

6270
M =
63-
kron(IMatrix(2), P1, Z, IMatrix(4), P1, IMatrix(4)) +
64-
kron(IMatrix(2), P0, IMatrix(8), P0, IMatrix(4)) +
65-
kron(IMatrix(2), P1, IMatrix(8), P0, IMatrix(4)) +
66-
kron(IMatrix(2), P0, IMatrix(8), P1, IMatrix(4))
71+
kron(eye(2), P1, Z, eye(4), P1, eye(4)) +
72+
kron(eye(2), P0, eye(8), P0, eye(4)) +
73+
kron(eye(2), P1, eye(8), P0, eye(4)) +
74+
kron(eye(2), P0, eye(8), P1, eye(4))
6775

6876
@test rrr M * V
6977
ic = itercontrol(4, [2, 3], [0, 0])

test/operations.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ msk = bmask(2, 5)
5656
@test bint_r(0.75, nbits = 3) == 6
5757
@test bint(0.75, nbits = 3) == 3
5858
end
59+
60+
@testset "random" begin
61+
@test rand_bitstr64(5) isa BitStr64{5}
62+
end

test/reorder.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using BitBasis, Random, LuxurySparse, SparseArrays, LinearAlgebra
2-
3-
= kron
4-
PA = pmrand(2)
5-
PB = pmrand(2)
6-
PC = pmrand(2)
7-
@test reorder(PC PB PA, [3, 1, 2]) PB PA PC
8-
@test invorder(PC PB PA) PA PB PC
1+
using BitBasis, Random, SparseArrays, LinearAlgebra
92

103
DA = Diagonal(randn(2))
114
DB = Diagonal(randn(2))

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using BitBasis
22
using Test
33

4+
const = kron
5+
46
@testset "test bit literal" begin
57
include("bit_str.jl")
68
end

0 commit comments

Comments
 (0)