In [154]:
Pkg.test("KroneckerMatrices")
In [5]:
using Gadfly
In [6]:
using DataFrames
In [175]:
A = rand(2,2)
B = rand(2,2)
C = rand(2,2)
D = kron(kron(A,B),C)
Out[175]:
In [103]:
using KroneckerMatrices
In [198]:
type Totemys{T}
As::Vector{AbstractMatrix{T}}
function Totemys(As::AbstractMatrix{T}...)
return new(As)
end
end
In [199]:
methods(Totemy)
Out[199]:
In [193]:
bob = Totem(rand(3,3),rand(3,3))
In [189]:
function h(tacos::Matrix...)
return tacos[1]
end
Out[189]:
In [190]:
h(rand(4,5),rand(2,2))
Out[190]:
In [175]:
tom = Tote(Matrix{Float64}[rand(2,2), rand(2,2), rand(3,3)])
In [169]:
bob = [A::Matrix{Float64} for A in Any[rand(2,2), rand(2,2), rand(3,3)]]
Out[169]:
In [170]:
Out[170]:
In [113]:
A = rand(2,3)
B = rand(3,4)
C = KroneckerProduct(A,B)
Out[113]:
In [109]:
sizes(C) = [size(term) for term in terms(C)]
Out[109]:
In [114]:
terms(C)
Out[114]:
In [149]:
tacos = [(2,2),(3,5),(4,4)]
Out[149]:
In [150]:
x,y = [[S...] for S in zip(tacos...)]
Out[150]:
In [151]:
y
Out[151]:
In [1]:
using Iterators
In [35]:
Ms = Any[rand(2,2) ones(3,3) rand(2,2)]
[prod([λs...])::Float64 for λs in product([eigvals(M) for M in Ms]...)]
Out[35]:
In [87]:
Ms,Ns = [[S...] for S in zip([(2,2),(3,3),(5,5)]...)]
Out[87]:
In [97]:
all(Ms .== Ns)
Out[97]:
In [89]:
K = prod(Ms)
Out[89]:
In [90]:
Ks = [div(K,M) for M in Ms]
Out[90]:
In [37]:
[prod([taco...]) for taco in product(tacos...)]
Out[37]:
In [151]:
A = ones(2,2)
B = rand(3,3)
C = kronproduct(A,B)
D = kronsum(A,B)
Out[151]:
In [45]:
EC,VC = eig(C)
ED,VD = eig(D)
Out[45]:
In [53]:
maximum(abs(C*D-D*C))
Out[53]:
In [39]:
all(issquare,terms(C))
Out[39]:
In [131]:
function spyy(A::AbstractMatrix)
M,N = size(A)
is, js, values = findnz(A)
df = DataFrames.DataFrame(i=is, j=js, value=values)
plot(df, x="j", y="i", color="value",
Coord.cartesian(yflip=true,fixed=true,ymin=1,ymax=M,xmin=1,xmax=N),
Guide.xlabel(""),Guide.ylabel(""),
Scale.color_continuous,
Theme(grid_line_width= 0pt),
Scale.x_continuous(maxvalue = N-5),
Scale.y_continuous(maxvalue = M-5),
Geom.rectbin,
Stat.identity)
end
Out[131]:
In [142]:
A = [1 1; 1 0]
Out[142]:
In [143]:
size(kronpower(A,5))
Out[143]:
In [147]:
tacobeast = spyy(kronpower(A,5))
Out[147]:
In [135]:
A = [1 1 1; 1 1 0; 1 0 0]
spyy(kronpower(A,3))
Out[135]:
In [82]:
boast = tacobeast.scales[2]
Out[82]:
In [92]:
boast.vars
Out[92]:
In [95]:
Scale.ContinuousScale()
In [32]:
A = [1 1 1 1 1; 1 1 1 1 0 ; 1 1 1 0 0; 1 1 0 1 1; 1 0 0 1 0]
Out[32]:
In [34]:
spyy(kronpower(A,2))
Out[34]:
In [172]:
P = [1,2,3,4]
N::Int = sqrt(length(P))
In [167]:
In [168]:
N::Int = 3
In [207]:
a = [1,2,3]
b = [1,1]
c = [4,3,2,1]
m = kron(kron(a,b),c)'
spark(m),m
Out[207]:
In [218]:
[mod(i-1,length(c)) for i in 1:24]'
Out[218]:
In [220]:
[mod(div(i-1,length(c)),length(b)) for i in 1:24]'
Out[220]:
In [222]:
[mod(div(i-1,length(c)*length(b)),length(a)) for i in 1:24]'
Out[222]:
In [230]:
function hindexes(i,widths)
indexes = zeros(Int64,length(widths))
q = 1
for (level,width) in enumerate(widths)
indexes[level] = mod(div(i-1,q),width)+1
q = q*width
end
return indexes
end
Out[230]:
In [293]:
Out[293]:
In [313]:
function hindexes(i::Int64,widths)
return [(mod(div(i-1,u),w)+1)::Int64 for (u,w) in zip(cumprod([1, widths]),widths)]
end
Out[313]:
In [275]:
widths = [4,2,3]
divisors = cumprod([1, widths])
Out[275]:
In [314]:
In [304]:
tacos = [(1,2),(3,4),(5,6)]
Out[304]:
In [305]:
x,y = zip(tacos...)
x,y
Out[305]:
In [312]:
typeof((1,"foo",2.5))
Out[312]:
In [292]:
widths = [4,2,3]
taco = [hindexes(i,widths) for i=1:24]
Out[292]:
In [251]:
x,y = zip([(1,2),(3,4),(5,6)]...)
Out[251]:
In [254]:
map(*,[(1,2),(3,4),(5,6)]...)
Out[254]:
In [ ]: