Created
October 1, 2014 14:43
-
-
Save sbchisholm/6cb74ca2be0d107480f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"language": "Julia", | |
"name": "ylt" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "type YLT\n data::Array{Float64}\nend", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt_index_map = {:net => 2, :gros => 1}", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 18, | |
"text": "{:net=>2,:gros=>1}" | |
} | |
], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt = YLT([1.2, 2.3, 3.4, 4.5])", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 19, | |
"text": "YLT([1.2,2.3,3.4,4.5])" | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "function getindex(ylt::YLT, index::Symbol)\n if index == :gros\n return ylt.data[ylt_index_map[index]:length(ylt_index_map):end]\n elseif index == :net\n return ylt.data[ylt_index_map[index]:length(ylt_index_map):end]\n else\n error(\"invalid symbol: $index\")\n end \nend\n\nfunction getindex(ylt::YLT, indices::Symbol...)\n r = Array(Float64, int64(length(ylt.data)/2), length(indices))\n for (i, index) in enumerate(indices)\n if index == :gros\n r[:,i] = ylt.data[ylt_index_map[index]:length(ylt_index_map):end]\n elseif index == :net\n r[:,i] = ylt.data[ylt_index_map[index]:length(ylt_index_map):end]\n else\n error(\"invalid symbol: $index\")\n end\n end\n return r\nend", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 23, | |
"text": "getindex (generic function with 142 methods)" | |
} | |
], | |
"prompt_number": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:net]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 24, | |
"text": "2-element Array{Float64,1}:\n 2.3\n 4.5" | |
} | |
], | |
"prompt_number": 24 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:gros]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 25, | |
"text": "2-element Array{Float64,1}:\n 1.2\n 3.4" | |
} | |
], | |
"prompt_number": 25 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:wrong]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "LoadError", | |
"evalue": "invalid symbol: wrong\nat In[26]:1", | |
"output_type": "pyerr", | |
"traceback": [ | |
"invalid symbol: wrong\nat In[26]:1", | |
" in error at error.jl:21", | |
" in getindex at In[23]:7" | |
] | |
} | |
], | |
"prompt_number": 26 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:net, :gros]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 27, | |
"text": "2x2 Array{Float64,2}:\n 2.3 1.2\n 4.5 3.4" | |
} | |
], | |
"prompt_number": 27 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt.data", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 28, | |
"text": "4-element Array{Float64,1}:\n 1.2\n 2.3\n 3.4\n 4.5" | |
} | |
], | |
"prompt_number": 28 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment