{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "full (generic function with 1 method)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# For kernel 0.4.5\n", "# This the original file, plus improved getindex() and isassigned()\n", "immutable Hankel{T} <: AbstractArray{T, 2}\n", " c :: Vector{T}\n", "end\n", "\n", "Hankel{T}(c::Vector{T}) = length(c) % 2 == 1 ? Hankel{T}(c) : throw(ArgumentError(\"\"))\n", "\n", "#XXX Inefficient but works\n", "# getindex(H::Hankel, i, j) = getindex(full(H), i, j)\n", "# isassigned(H::Hankel, i, j) = isassigned(full(H), i, j)\n", "import Base.getindex, Base.isassigned, Base.size\n", "getindex(H::Hankel, i, j) = H.c[i+j-1]\n", "isassigned(H::Hankel,i,j) = isassigned(H.c,i+j-1)\n", "size(H::Hankel, r::Int) = (r==1 || r==2) ? 1 + div(length(H.c),2) :\n", " throw(ArgumentError(\"Invalid dimension $r\"))\n", "size(H::Hankel) = size(H,1), size(H,2)\n", "\n", "function full{T}(H::Hankel{T})\n", " n=size(H, 1)\n", " M=Array(T, n, n)\n", " for i=1:n\n", " M[:,i] = H.c[i:i+n-1]\n", " end\n", " M\n", "end" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "6x6 Hankel{Int64}:\n", " 1 2 3 4 5 6\n", " 2 3 4 5 6 7\n", " 3 4 5 6 7 8\n", " 4 5 6 7 8 9\n", " 5 6 7 8 9 10\n", " 6 7 8 9 10 11" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a=collect(1:11)\n", "H=Hankel(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now change the kernel to 5.0" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: Method definition (::Type{Main.Hankel})(Array{#T<:Any, 1}) in module Main at In[1]:3 overwritten at In[1]:6.\n" ] }, { "data": { "text/plain": [ "full (generic function with 1 method)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# After kernel change to 5.0\n", "immutable Hankel{T} <: AbstractArray{T, 2}\n", " c :: Vector{T}\n", "end\n", "\n", "Hankel{T}(c::Vector{T}) = length(c) % 2 == 1 ? Hankel{T}(c) : throw(ArgumentError(\"\"))\n", "\n", "#XXX Inefficient but works\n", "# getindex(H::Hankel, i, j) = getindex(full(H), i, j)\n", "# isassigned(H::Hankel, i, j) = isassigned(full(H), i, j)\n", "import Base.getindex, Base.isassigned, Base.size\n", "getindex(H::Hankel, i, j) = H.c[i+j-1]\n", "isassigned(H::Hankel,i,j) = isassigned(H.c,i+j-1)\n", "size(H::Hankel, r::Int) = (r==1 || r==2) ? 1 + div(length(H.c),2) :\n", " throw(ArgumentError(\"Invalid dimension $r\"))\n", "size(H::Hankel) = size(H,1), size(H,2)\n", "\n", "function full{T}(H::Hankel{T})\n", " n=size(H, 1)\n", " M=Array(T, n, n)\n", " for i=1:n\n", " M[:,i] = H.c[i:i+n-1]\n", " end\n", " M\n", "end" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "ename": "MethodError", "evalue": "MethodError: isassigned(::Hankel{Int64}, ::Int64, ::Int64) is ambiguous. Candidates:\n isassigned(H::Hankel, i, j) at In[1]:13\n isassigned(a::AbstractArray, i::Int64...) at abstractarray.jl:185", "output_type": "error", "traceback": [ "MethodError: isassigned(::Hankel{Int64}, ::Int64, ::Int64) is ambiguous. Candidates:\n isassigned(H::Hankel, i, j) at In[1]:13\n isassigned(a::AbstractArray, i::Int64...) at abstractarray.jl:185", "", " in alignment(::IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::Hankel{Int64}, ::Array{Int64,1}, ::Array{Int64,1}, ::Int64, ::Int64, ::Int64) at ./show.jl:1277", " in print_matrix(::IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::Hankel{Int64}, ::String, ::String, ::String, ::String, ::String, ::String, ::Int64, ::Int64) at ./show.jl:1407", " in print_matrix(::IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::Hankel{Int64}, ::String, ::String, ::String) at ./show.jl:1379", " in #showarray#330(::Bool, ::Function, ::IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::Hankel{Int64}, ::Bool) at ./show.jl:1618", " in limitstringmime(::MIME{Symbol(\"text/plain\")}, ::Hankel{Int64}) at /home/slap/.julia/v0.5/IJulia/src/execute_request.jl:31", " in display_dict(::Hankel{Int64}) at /home/slap/.julia/v0.5/IJulia/src/execute_request.jl:46", " in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /home/slap/.julia/v0.5/IJulia/src/execute_request.jl:200", " in eventloop(::ZMQ.Socket) at /home/slap/.julia/v0.5/IJulia/src/eventloop.jl:8", " in (::IJulia.##9#15)() at ./task.jl:360" ] } ], "source": [ "a=collect(1:11)\n", "Hankel(a)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.4.5", "language": "julia", "name": "julia-0.4" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.4.5" } }, "nbformat": 4, "nbformat_minor": 0 }