In [154]:
Pkg.test("KroneckerMatrices")


INFO: Testing KroneckerMatrices
INFO: KroneckerMatrices tests passed
INFO: No packages to install, update or remove

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]:
8x8 Array{Float64,2}:
 0.0879228  0.000941934  0.140782   …  0.00140191  0.209532   0.00224475 
 0.060426   0.137032     0.0967545     0.20395     0.144003   0.326567   
 0.104792   0.00112266   0.0328767     0.0016709   0.0489316  0.000524213
 0.0720199  0.163325     0.0225949     0.243082    0.0336288  0.0762625  
 0.129538   0.00138776   0.207417      0.00249661  0.373146   0.00399759 
 0.0890266  0.201892     0.14255    …  0.363207    0.25645    0.581569   
 0.154392   0.00165403   0.0484377     0.00297563  0.0871402  0.000933549
 0.106108   0.240629     0.0332894     0.432895    0.0598882  0.135813   

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]:
0 methods for generic function Totemy:
    
    
    In [193]:
    bob = Totem(rand(3,3),rand(3,3))
    
    
    
    
    `Totem{T}` has no method matching Totem{T}(::Array{Float64,2}, ::Array{Float64,2})
    while loading In[193], in expression starting on line 1
    
    
    
    In [189]:
    function h(tacos::Matrix...)
        return tacos[1]
    end
    
    
    
    
    Out[189]:
    h (generic function with 1 method)
    
    
    In [190]:
    h(rand(4,5),rand(2,2))
    
    
    
    
    Out[190]:
    4x5 Array{Float64,2}:
     0.0298125  0.0177663  0.231527  0.834273  0.555125
     0.821613   0.233224   0.829963  0.798345  0.745574
     0.777108   0.158121   0.958504  0.750942  0.506544
     0.551758   0.302045   0.598882  0.346077  0.022479
    
    
    In [175]:
    tom = Tote(Matrix{Float64}[rand(2,2), rand(2,2), rand(3,3)])
    
    
    
    
    `Tote{T}` has no method matching Tote{T}(::Array{Array{Float64,2},1})
    while loading In[175], in expression starting on line 1
    
    
    
    In [169]:
    bob = [A::Matrix{Float64} for A in Any[rand(2,2), rand(2,2), rand(3,3)]]
    
    
    
    
    Out[169]:
    3-element Array{Array{Float64,2},1}:
     2x2 Array{Float64,2}:
     0.409277  0.512014
     0.427051  0.291574                                                  
     2x2 Array{Float64,2}:
     0.126504  0.819804
     0.685401  0.777144                                                  
     3x3 Array{Float64,2}:
     0.51315   0.553133  0.173845
     0.837948  0.509068  0.641668
     0.702207  0.221764  0.287606
    
    
    In [170]:
    
    
    
    
    
    Out[170]:
    3-element Array{Array{Float64,2},1}:
     2x2 Array{Float64,2}:
     0.023356  0.320177
     0.589151  0.145525                                                        
     2x2 Array{Float64,2}:
     0.0434465  0.630183
     0.0610082  0.274149                                                      
     3x3 Array{Float64,2}:
     0.995517   0.0465565  0.22003 
     0.0562721  0.157457   0.421315
     0.572043   0.723058   0.876339
    
    
    In [113]:
    A = rand(2,3)
    B = rand(3,4)
    C = KroneckerProduct(A,B)
    
    
    
    
    Out[113]:
    6x12 KroneckerProduct{Float64}:
     0.0595408  0.369519  0.585423  …  0.00433052  0.0268759  0.042579 
     0.506168   0.636393  0.967985     0.0368147   0.0462862  0.0704035
     0.042217   0.262005  0.415091     0.0254345   0.15785    0.25008  
     0.358895   0.451231  0.686344     0.216224    0.271854   0.413503 
     0.0594453  0.368926  0.584484     0.0553461   0.343486   0.54418  
     0.505357   0.635373  0.966433  …  0.470509    0.59156    0.899791 
    
    
    In [109]:
    sizes(C) = [size(term) for term in terms(C)]
    
    
    
    
    Out[109]:
    sizes (generic function with 1 method)
    
    
    In [114]:
    terms(C)
    
    
    
    
    Out[114]:
    (
    2x3 Array{Float64,2}:
     0.059776  0.370979  0.587736
     0.508168  0.638908  0.971809,
    
    3x4 Array{Float64,2}:
     0.996065  0.983974  0.899303  0.0724458
     0.706254  0.816492  0.848316  0.425498 
     0.994468  0.732049  0.56052   0.925893 )
    
    
    In [149]:
    tacos = [(2,2),(3,5),(4,4)]
    
    
    
    
    Out[149]:
    3-element Array{(Int64,Int64),1}:
     (2,2)
     (3,5)
     (4,4)
    
    
    In [150]:
    x,y = [[S...] for S in zip(tacos...)]
    
    
    
    
    Out[150]:
    2-element Array{Any,1}:
     [2,3,4]
     [2,5,4]
    
    
    In [151]:
    y
    
    
    
    
    Out[151]:
    3-element Array{Int64,1}:
     2
     5
     4
    
    
    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]:
    12-element Array{Float64,1}:
     -3.10224e-17
     -2.8891e-16 
      4.02956e-19
      3.75271e-18
      0.165477   
      1.54108    
      3.18059e-18
      2.96207e-17
     -4.13133e-20
     -3.84749e-19
     -0.0169657  
     -0.158      
    
    
    In [87]:
    Ms,Ns = [[S...] for S in  zip([(2,2),(3,3),(5,5)]...)]
    
    
    
    
    Out[87]:
    2-element Array{Any,1}:
     [2,3,5]
     [2,3,5]
    
    
    In [97]:
    all(Ms .== Ns)
    
    
    
    
    Out[97]:
    false
    
    
    In [89]:
    K = prod(Ms)
    
    
    
    
    Out[89]:
    30
    
    
    In [90]:
    Ks = [div(K,M) for M in Ms]
    
    
    
    
    Out[90]:
    3-element Array{Any,1}:
     15
     10
      6
    
    
    In [37]:
    [prod([taco...]) for taco in product(tacos...)]
    
    
    
    
    Out[37]:
    24-element Array{Any,1}:
     1.0
     2.0
     3.0
     1.0
     2.0
     3.0
     1.0
     2.0
     3.0
     1.0
     2.0
     3.0
     2.0
     4.0
     6.0
     2.0
     4.0
     6.0
     2.0
     4.0
     6.0
     2.0
     4.0
     6.0
    
    
    In [151]:
    A = ones(2,2)
    B = rand(3,3)
    C = kronproduct(A,B)
    D = kronsum(A,B)
    
    
    
    
    Out[151]:
    6x6 Array{Float64,2}:
     1.65115   0.670688  0.790988  1.0       0.0       0.0     
     0.182858  1.39992   0.644648  0.0       1.0       0.0     
     0.57719   0.229437  1.82013   0.0       0.0       1.0     
     1.0       0.0       0.0       1.65115   0.670688  0.790988
     0.0       1.0       0.0       0.182858  1.39992   0.644648
     0.0       0.0       1.0       0.57719   0.229437  1.82013 
    
    
    In [45]:
    EC,VC = eig(C)
    ED,VD = eig(D)
    
    
    
    
    Out[45]:
    ([2.14702,-0.596853,1.34104,0.998677,0.192693,0.209131],
    6x6 Array{Float64,2}:
     0.175534   0.505391   0.510511   0.0862698   0.250901   -0.173774
     0.194734  -0.709849   0.566351   0.165621    0.48168     0.244074
     0.206082   0.425787   0.599354  -0.27628    -0.803514   -0.146403
     0.496254  -0.127004  -0.12829    0.243894   -0.0630508  -0.491277
     0.550534   0.178383  -0.142323   0.468227   -0.121045    0.690025
     0.582616  -0.106999  -0.150616  -0.781073    0.201921   -0.413896)
    
    
    In [53]:
    maximum(abs(C*D-D*C))
    
    
    
    
    Out[53]:
    1.1102230246251565e-16
    
    
    In [39]:
    all(issquare,terms(C))
    
    
    
    
    Out[39]:
    7 methods for generic function all:
    
    
    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]:
    spyy (generic function with 1 method)
    
    
    In [142]:
    A = [1 1; 1 0]
    
    
    
    
    Out[142]:
    2x2 Array{Int64,2}:
     1  1
     1  0
    
    
    In [143]:
    size(kronpower(A,5))
    
    
    
    
    Out[143]:
    (64,64)
    
    
    In [147]:
    tacobeast = spyy(kronpower(A,5))
    
    
    
    
    Out[147]:
    -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 -60 -58 -56 -54 -52 -50 -48 -46 -44 -42 -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 -100 0 100 200 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 1 value -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 -60 -58 -56 -54 -52 -50 -48 -46 -44 -42 -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 -100 0 100 200 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120
    
    
    In [135]:
    A = [1 1 1; 1 1 0; 1 0 0]
    spyy(kronpower(A,3))
    
    
    
    
    Out[135]:
    -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 -100 0 100 200 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 1 value -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 -100 0 100 200 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160
    
    
    In [82]:
    boast = tacobeast.scales[2]
    
    
    
    
    Out[82]:
    ContinuousScale([:x,:xmin,:xmax,:xintercept,:xviewmin,:xviewmax],ContinuousScaleTransform(identity,identity,identity_formatter),nothing,nothing,2,10,nothing,nothing,true)
    
    
    In [92]:
    boast.vars
    
    
    
    
    Out[92]:
    6-element Array{Symbol,1}:
     :x         
     :xmin      
     :xmax      
     :xintercept
     :xviewmin  
     :xviewmax  
    
    
    In [95]:
    Scale.ContinuousScale()
    
    
    
    
    ContinuousScaleTransform not defined
    while loading In[95], in expression starting on line 1
    
    
    
    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]:
    5x5 Array{Int64,2}:
     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
    
    
    In [34]:
    spyy(kronpower(A,2))
    
    
    
    
    Out[34]:
    -200 -150 -100 -50 0 50 100 150 200 250 300 350 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265 270 275 280 285 290 295 300 -200 0 200 400 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 1 value -200 -150 -100 -50 0 50 100 150 200 250 300 350 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265 270 275 280 285 290 295 300 -200 0 200 400 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300
    
    
    In [172]:
    P = [1,2,3,4]
    N::Int = sqrt(length(P))
    
    
    
    
    type: typeassert: expected Int64, got Float64
    while loading In[172], in expression starting on line 2
    
    
    
    In [167]:
    
    
    
    
    
    N not defined
    while loading In[167], in expression starting on line 1
    
    
    
    In [168]:
    N::Int = 3
    
    
    
    
    N not defined
    while loading In[168], in expression starting on line 1
    
    
    
    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]:
    (nothing,
    1x24 Array{Int64,2}:
     4  3  2  1  4  3  2  1  8  6  4  2  8  6  4  2  12  9  6  3  12  9  6  3)
    
    
    In [218]:
    [mod(i-1,length(c)) for i in 1:24]'
    
    
    
    
    Out[218]:
    1x24 Array{Any,2}:
     0  1  2  3  0  1  2  3  0  1  2  3  0  1  2  3  0  1  2  3  0  1  2  3
    
    
    In [220]:
    [mod(div(i-1,length(c)),length(b)) for i in 1:24]'
    
    
    
    
    Out[220]:
    1x24 Array{Any,2}:
     0  0  0  0  1  1  1  1  0  0  0  0  1  1  1  1  0  0  0  0  1  1  1  1
    
    
    In [222]:
    [mod(div(i-1,length(c)*length(b)),length(a)) for i in 1:24]'
    
    
    
    
    Out[222]:
    1x24 Array{Any,2}:
     0  0  0  0  0  0  0  0  1  1  1  1  1  1  1  1  2  2  2  2  2  2  2  2
    
    
    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]:
    hindexes (generic function with 1 method)
    
    
    In [293]:
    
    
    
    
    
    Out[293]:
    hindexes (generic function with 2 methods)
    
    
    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]:
    hindexes (generic function with 3 methods)
    
    
    In [275]:
    widths = [4,2,3]
    divisors = cumprod([1, widths])
    
    
    
    
    Out[275]:
    4-element Array{Int64,1}:
      1
      4
      8
     24
    
    
    In [314]:
    
    
    
    
    
    KroneckerMatrix not defined
    while loading In[314], in expression starting on line 1
    
    
    
    In [304]:
    tacos = [(1,2),(3,4),(5,6)]
    
    
    
    
    Out[304]:
    3-element Array{(Int64,Int64),1}:
     (1,2)
     (3,4)
     (5,6)
    
    
    In [305]:
    x,y = zip(tacos...)
    x,y
    
    
    
    
    Out[305]:
    ((1,3,5),(2,4,6))
    
    
    In [312]:
    typeof((1,"foo",2.5))
    
    
    
    
    Out[312]:
    (Int64,ASCIIString,Float64)
    
    
    In [292]:
    widths = [4,2,3]
    taco = [hindexes(i,widths) for i=1:24]
    
    
    
    
    Out[292]:
    2-element Array{Array{Int64,N},1}:
     [1,1,1]
     [2,1,1]
    
    
    In [251]:
    x,y = zip([(1,2),(3,4),(5,6)]...)
    
    
    
    
    Out[251]:
    Zip{((Int64,Int64),(Int64,Int64),(Int64,Int64))}(((1,2),(3,4),(5,6)))
    
    
    In [254]:
    map(*,[(1,2),(3,4),(5,6)]...)
    
    
    
    
    Out[254]:
    (15,48)
    
    
    In [ ]: