Copy disabled (too large)
Download .txt
Showing preview only (10,221K chars total). Download the full file to get everything.
Repository: juanklopper/JuliaCourseNotebooks
Branch: master
Commit: b1649389ffcc
Files: 44
Total size: 9.7 MB
Directory structure:
gitextract_pjvm24r9/
├── .gitattributes
├── .gitignore
├── .ipynb_checkpoints/
│ ├── Collections_using_v_1-checkpoint.ipynb
│ ├── Week 3_Peer graded quiz on Types-checkpoint.ipynb
│ ├── Week 4_Peer graded quiz on Gadfly-checkpoint.ipynb
│ ├── Week 4_Peer graded quiz on data-checkpoint.ipynb
│ ├── Week3_Honors1-Types-checkpoint.ipynb
│ └── Week4_4Data-checkpoint.ipynb
├── CCS.csv
├── Collections.ipynb
├── Collections_using_v_1.ipynb
├── Countries.csv
├── Functions.ipynb
├── Functions_using_v_1.ipynb
├── GadflyTutorialData.csv
├── Indicators.csv
├── README.md
├── Week 3_Peer graded quiz on Types.ipynb
├── Week 4_Peer graded quiz on Gadfly.ipynb
├── Week 4_Peer graded quiz on data.ipynb
├── Week1_1-WhySpecial.ipynb
├── Week1_2-JuliaBox.ipynb
├── Week1_3-REPL.ipynb
├── Week1_4-ArithmeticalExp.ipynb
├── Week1_5-LogicalExp.ipynb
├── Week1_6-TypeSystem.ipynb
├── Week1_7-Variables.ipynb
├── Week1_8-Functions1.ipynb
├── Week1_9-Functions2.ipynb
├── Week2_1-EbolaExample.ipynb
├── Week2_2_1-LoadingData.ipynb
├── Week2_2_2_CreateCSV.ipynb
├── Week2_3-ForLoops.ipynb
├── Week2_4-SimplePlots.ipynb
├── Week2_5-MultipleCurves.ipynb
├── Week3_1-SIRmodels.ipynb
├── Week3_2-MoreSIR.ipynb
├── Week3_3-PlottingData.ipynb
├── Week3_4-RoughFit.ipynb
├── Week3_Honors1-Types.ipynb
├── Working with data_using_v_1.ipynb
├── style.css
├── wikipediaEVDdatesconverted.csv
└── wikipediaEVDraw.csv
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
================================================
FILE: .gitignore
================================================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
================================================
FILE: .ipynb_checkpoints/Collections_using_v_1-checkpoint.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Collections"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## In this lecture"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- [Introduction](#Introduction)\n",
"- [Arrays](#Arrays)\n",
"- [Tuples](#Tuples)\n",
"- [Dictionaries](#Dictionaries)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Collections are groups of elements. These elements are values of different Julia types. Storing elements in collections is one of the most useful operations in computing."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Arrays"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Arrays are collections of values separated with commas and placed inside of a set of square brackets. They can be represented in column or in row form."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A column vector\n",
"array1 = [1, 2, 3]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `typeof()` function shows that `array1` is an instance of an array object, containing integer values."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The type of the object array1\n",
"typeof(array1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below we create `array2`. Note that there are only spaces between the elements."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1×3 Array{Int64,2}:\n",
" 1 2 3"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# A row vector\n",
"array2 = [1 2 3]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `transpose()` function will create a linear algebra transpose of our column vector, `array1`."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1×3 LinearAlgebra.Transpose{Int64,Array{Int64,1}}:\n",
" 1 2 3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The transpose\n",
"transpose(array1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When the types of the elements are not the same, all elements _inherit_ the _highest_ type."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Float64,1}:\n",
" 1.0\n",
" 2.0\n",
" 3.0"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# With a mix of types, all the elements inherent the \"highest\" type\n",
"array2 = [1, 2, 3.0]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Index for one of the original integers will be Float64\n",
"array2[1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Arrays can have more than one _dimension_ (here dimension does not refer to the number of elements in a vector, representing a vector field)."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Int64,2}:\n",
" 1 4 7\n",
" 2 5 8\n",
" 3 6 9"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Column-wise entry of multidimensional array\n",
"array3 = [[1, 2, 3] [4, 5, 6] [7, 8, 9]]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Int64,2}:\n",
" 1 2 3\n",
" 4 5 6\n",
" 7 8 9"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Row-wise entry of multidimensional array\n",
"array4 = [[1 2 3]; [4 5 6]; [7 8 9]]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `length()` function returns the number of elements."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Length of array3\n",
"length(array3)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length(array4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since the two arrays above were created differently, let's take a look at indexes of their elements."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Element 1 is 1\n",
"Element 2 is 2\n",
"Element 3 is 3\n",
"Element 4 is 4\n",
"Element 5 is 5\n",
"Element 6 is 6\n",
"Element 7 is 7\n",
"Element 8 is 8\n",
"Element 9 is 9\n"
]
}
],
"source": [
"# Index order of column-wise array\n",
"for i in 1:length(array3)\n",
" println(\"Element $(i) is \", array3[i])\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Element 1 is 1\n",
"Element 2 is 4\n",
"Element 3 is 7\n",
"Element 4 is 2\n",
"Element 5 is 5\n",
"Element 6 is 8\n",
"Element 7 is 3\n",
"Element 8 is 6\n",
"Element 9 is 9\n"
]
}
],
"source": [
"# Index order of row-wise array\n",
"for i in 1:length(array4)\n",
" println(\"Element $(i) is \", array4[i])\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Elements can be repeated using the `repeat()` function."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 1\n",
" 2\n",
" 1\n",
" 2"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using repeat() to repeat column elements\n",
"repeat([1, 2], 3)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×2 Array{Int64,2}:\n",
" 1 2\n",
" 1 2\n",
" 1 2"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using repeat() to repeat row elements\n",
"repeat([1 2], 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `range()` function creates a range object. The first argument is the value of the first element. The `step = ` argument specifies the step-size, and the `length =` argument specifies how many elements the array should have."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1:1:10"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using range(start, step, number of elements)\n",
"range(1, step = 1, length = 10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can change the range object into an array using the `collect()` function."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3\n",
" 4\n",
" 5\n",
" 6\n",
" 7\n",
" 8\n",
" 9\n",
" 10"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create collections using the collect() function\n",
"collect(range(1, step = 1, length = 10))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3\n",
" 4\n",
" 5\n",
" 6\n",
" 7\n",
" 8\n",
" 9\n",
" 10"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Short-hand syntax\n",
"collect(1:10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can create empty arrays as placeholders."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×3 Array{Union{Missing, Int64},2}:\n",
" missing missing missing\n",
" missing missing missing"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Creating empty array with two rows and three columns\n",
"array5 = Array{Union{Missing, Int}}(missing, 2, 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Reshaping is achieved using the `reshape()` function."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×2 Array{Union{Missing, Int64},2}:\n",
" missing missing\n",
" missing missing\n",
" missing missing"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Reshaping\n",
"reshape(array5, 3, 2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Every element in an arrays has an index (address) value. We already saw this above when we created a for-loop to cycle through the values of our row vs. column created arrays."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10×5 Array{Int64,2}:\n",
" 18 20 13 18 13\n",
" 16 14 14 12 16\n",
" 14 13 11 19 20\n",
" 19 11 10 12 14\n",
" 20 15 15 14 12\n",
" 11 20 20 10 20\n",
" 10 15 17 13 12\n",
" 11 17 13 14 16\n",
" 18 10 16 15 10\n",
" 12 13 18 14 10"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Creating a 10 x 5 array with each element drawn randomly from value 10 through 20\n",
"array6 = rand(10:20, 10, 5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Indexing is indicated with square brackets. For arrays with rows and columns, the index values will be in the form `[row, column]`. A colon serves as short-hand syntax indicating _all_ values."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Int64,1}:\n",
" 18\n",
" 16\n",
" 14\n",
" 19\n",
" 20\n",
" 11\n",
" 10\n",
" 11\n",
" 18\n",
" 12"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#All rows in first column\n",
"array6[:, 1]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Int64,1}:\n",
" 14\n",
" 13\n",
" 11\n",
" 15"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Rows two through five of second column\n",
"array6[2:5, 2]"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×2 Array{Int64,2}:\n",
" 16 16\n",
" 19 14\n",
" 11 20"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Values in rows 2, 4, 6, and in columns 1 and 5\n",
"array6[[2, 4, 6], [1, 5]]"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 13\n",
" 18\n",
" 13"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Values in row 1 from column 3 to the last column\n",
"array6[1, 3:end]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Boolean logic can be used to select values based on rules. Below we check if each value in column one is equal to or greater than $12$."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element BitArray{1}:\n",
" true\n",
" true\n",
" true\n",
" true\n",
" true\n",
" false\n",
" false\n",
" false\n",
" true\n",
" false"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Boolean logic (returning only true or false)\n",
"array6[:, 1] .> 12"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can add values to an array using the `push!()` function. Many functions in Julia have an added exclamation mark, called a _bang_. It is used to make permanent changes to the values in a computer variable."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3\n",
" 4\n",
" 5\n",
" 10"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Creating a five element array\n",
"array7 = [1, 2, 3, 4, 5]\n",
"# Permanantly append 10 to end of array\n",
"push!(array7, 10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `pop!()` function removes the last element (the bang makes it permanent)."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pop!(array7)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also change the value of an element by using its index."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1000"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Change second element value to 1000\n",
"array7[2] = 1000"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5-element Array{Int64,1}:\n",
" 1\n",
" 1000\n",
" 3\n",
" 4\n",
" 5"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Viewing the change\n",
"array7"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_List comprehension_ is a term that refers to the creating of an array using a _recipe_. View the following example."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5-element Array{Int64,1}:\n",
" 3\n",
" 6\n",
" 9\n",
" 12\n",
" 15"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# An example of list comprehension\n",
"array8 = [3 * i for i in 1:5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Julia syntax is very expressive, as the above example shows. Square brackets indicate that we are creating a list. The expression, `3 * i` indicates what we want each element to look like. The for-loop uses the placeholder over which we wish to iterate, together with the range that we require."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This allows for very complex array creation, which makes it quite versatile."
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Int64,2}:\n",
" 1 2 3\n",
" 2 4 6\n",
" 3 6 9"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Column-wise collection iterating through second element first\n",
"array9 = [a * b for a in 1:3, b in 1:3]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Arithmetic operations on arrays are performed through the process of _broadcasting_. Below we add $1$ to each element in `array9`."
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Int64,2}:\n",
" 2 3 4\n",
" 3 5 7\n",
" 4 7 10"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Elementwise addition of a scalar using dot notation\n",
"array9 .+ 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When arrays are of similar shape, we can do elemnt wise addition."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5-element Array{Int64,1}:\n",
" 4\n",
" 1006\n",
" 12\n",
" 16\n",
" 20"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Elementwise addition of similar sized arrays\n",
"array7 + array8"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"While it is nice to have a complete set of elements, data is often _missing_. `Missing` is a Julia data type that provides a placeholder for missing data in a statistical sense. It propagates automatically and its equality as a type can be tested. Sorting is possible since missing is seen as greater than other values."
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"missing"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Propagation\n",
"missing + 1"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"missing"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"missing > 1"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5-element Array{Union{Missing, Int64},1}:\n",
" 11 \n",
" 22 \n",
" 33 \n",
" missing\n",
" 55 "
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[1, 2, 3, missing, 5] + [10, 20, 30, 40 ,50]"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"missing"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Checking equality of value using ==\n",
"# Cannot return true or false since value is not known\n",
"missing == missing"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Checking equality of type with ===\n",
"missing === missing"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Checking type equality with isequal()\n",
"isequal(missing, missing)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Sorting with isless()\n",
"isless(1, missing)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Checking on infinity\n",
"isless(Inf, missing)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can create an array of zeros."
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Int8,2}:\n",
" 0 0 0\n",
" 0 0 0\n",
" 0 0 0"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# A 3 x 3 array of integer zeros\n",
"array11 = zeros(Int8, 3, 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here is an array of ones."
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Float16,2}:\n",
" 1.0 1.0 1.0\n",
" 1.0 1.0 1.0\n",
" 1.0 1.0 1.0"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# A 3 x 3 array of floating point ones\n",
"array12 = ones(Float16, 3, 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Boolean values are also allowed."
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 BitArray{2}:\n",
" true true true\n",
" true true true\n",
" true true true"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Array of true (bit array) values\n",
"array13 = trues(3, 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can even fill an array with a specified value."
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Int64,2}:\n",
" 10 10 10\n",
" 10 10 10\n",
" 10 10 10"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Fill an array with elements of value x\n",
"array14 = fill(10, 3, 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We have already seen that elemnts of different types all inherit the _highest_ type. We can in fact, change the type manually, with the convert function. As elsewhere in Julia, the dot opetaror maps the function to each element of a list."
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Array{Float16,2}:\n",
" 10.0 10.0 10.0\n",
" 10.0 10.0 10.0\n",
" 10.0 10.0 10.0"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Convert elements to a different data type\n",
"convert.(Float16, array14)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Arrays can be concatenated."
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3\n",
" 10\n",
" 20\n",
" 30"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Concatenate arrays along rows (makes rows)\n",
"array15 = [1, 2, 3]\n",
"array16 = [10, 20, 30]\n",
"cat(array15, array16, dims = 1)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3\n",
" 10\n",
" 20\n",
" 30"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Same as above\n",
"vcat(array15, array16)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×2 Array{Int64,2}:\n",
" 1 10\n",
" 2 20\n",
" 3 30"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Concatenate arrays along columns (makes columns)\n",
"cat(array15, array16, dims = 2)"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×2 Array{Int64,2}:\n",
" 1 10\n",
" 2 20\n",
" 3 30"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Same as above\n",
"hcat(array15, array16)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tuples"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tuples are immutable collections. Immutable refers to the fact that the values are set and cannot be changed. This type is indicated by the use of parenthesis instead of square brackets."
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 2.0, π = 3.1415926535897..., 4, \"Julia\")"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Tuples with mixed types\n",
"tuple1 = (1, 2., π, 4, \"Julia\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's check on the values and types of each element."
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" The value of the tuple at index number 1 is 1 and the type is Int64.\n",
" The value of the tuple at index number 2 is 2.0 and the type is Float64.\n",
" The value of the tuple at index number 3 is π = 3.1415926535897... and the type is Irrational{:π}.\n",
" The value of the tuple at index number 4 is 4 and the type is Int64.\n",
" The value of the tuple at index number 5 is Julia and the type is String.\n"
]
}
],
"source": [
"# For loop to look at value and type of each element\n",
"for i in 1:length(tuple1)\n",
" println(\" The value of the tuple at index number $(i) is $(tuple1[i]) and the type is $(typeof(tuple1[i])).\")\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tuples are useful as each elemnt can be named."
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Each element can be named\n",
"a, b, c, seven = (1, 3, 5, 7)\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"seven"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A range can be used to reverse the order of a tuple."
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(\"Julia\", 4, π = 3.1415926535897..., 2.0, 1)"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Reverse order index (can be done with arrays too)\n",
"tuple1[end:-1:1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Arrays can be made up of elemnts of different length."
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((1, 2, 3), 1, 2, (3, 100, 1))"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Mixed length tuples\n",
"tuple2 = ((1, 2, 3), 1, 2, (3, 100, 1))"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 100, 1)"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Element 4\n",
"tuple2[4]"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Element 2 in element 4\n",
"tuple2[4][2]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dictionaries"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Dictionaries are collection sof key-value pairs."
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Int64,Int64} with 3 entries:\n",
" 2 => 66\n",
" 3 => 1\n",
" 1 => 77"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 1 Example of a dictionary\n",
"dictionary1 = Dict(1 => 77, 2 => 66, 3 => 1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the example above we have key-values of `1,2,3` and value-values of `77,66,1`."
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Int64,Int64} with 3 entries:\n",
" 2 => 200\n",
" 3 => 300\n",
" 1 => 100"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The => is shorthand for the Pair() function\n",
"dictionary2 = Dict(Pair(1,100), Pair(2,200), Pair(3,300))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can specify the types used in a dict."
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Any,Any} with 3 entries:\n",
" 2 => 66\n",
" 3 => \"three\"\n",
" 1 => 77"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 2 Specifying types\n",
"dictionary3 = Dict{Any, Any}(1 => 77, 2 => 66, 3 => \"three\")"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Any,Any} with 2 entries:\n",
" (2, 3) => \"hello\"\n",
" \"a\" => 1"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We can get a bit crazy\n",
"dictionary4 = Dict{Any, Any}(\"a\" => 1, (2, 3) => \"hello\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is perhaps more useful to use symbols (colon symbol and a name) as key values. We can then refer to the key-name when we want to inquire about its value."
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"300"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using symbols as keys\n",
"dictionary5 = Dict(:A => 300, :B => 305, :C => 309)\n",
"dictionary5[:A]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can check on the key-value pairs in a dictionary."
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using in() to check on key-value pairs\n",
"in((:A => 300), dictionary5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Change value using the key is easy to perform."
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Symbol,Int64} with 3 entries:\n",
" :A => 300\n",
" :B => 305\n",
" :C => 1000"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Changing an existing value\n",
"dictionary5[:C] = 1000\n",
"dictionary5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `delete!()` function permanently deletes a key-value pair."
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Symbol,Int64} with 2 entries:\n",
" :B => 305\n",
" :C => 1000"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using the delete!() function\n",
"delete!(dictionary5, :A)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can list both the keys and the values in a dictionary."
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Base.KeySet for a Dict{Symbol,Int64} with 2 entries. Keys:\n",
" :B\n",
" :C"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The keys of a dictionary\n",
"keys(dictionary5)"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Base.ValueIterator for a Dict{Symbol,Int64} with 2 entries. Values:\n",
" 305\n",
" 1000"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"values(dictionary5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Through the use of iteration, we can get creative in the creation and interrogation of a dictionary."
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [],
"source": [
"# Creating a dictionary with automatic keys\n",
"procedure_vals = [\"Appendectomy\", \"Colectomy\", \"Cholecystectomy\"]\n",
"procedure_dict = Dict{AbstractString,AbstractString}() # An empty dictionary with types specified\n",
"for (s, n) in enumerate(procedure_vals)\n",
" procedure_dict[\"x_$(s)\"] = n\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{AbstractString,AbstractString} with 3 entries:\n",
" \"x_1\" => \"Appendectomy\"\n",
" \"x_2\" => \"Colectomy\"\n",
" \"x_3\" => \"Cholecystectomy\""
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"procedure_dict"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x_1 is Appendectomy\n",
"x_2 is Colectomy\n",
"x_3 is Cholecystectomy\n"
]
}
],
"source": [
"# Iterating through a dictionary by key and value\n",
"for (k, v) in procedure_dict\n",
" println(k, \" is \",v)\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lastly, we can sort using iteration."
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a is 1\n",
"b is 2\n",
"c is 3\n",
"d is 4\n",
"e is 5\n",
"f is 6\n"
]
}
],
"source": [
"# Sorting\n",
"dictionary6 = Dict(\"a\"=> 1,\"b\"=>2 ,\"c\"=>3 ,\"d\"=>4 ,\"e\"=>5 ,\"f\"=>6)\n",
"# Sorting using a for loop\n",
"for k in sort(collect(keys(dictionary6)))\n",
" println(\"$(k) is $(dictionary6[k])\")\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.0.3",
"language": "julia",
"name": "julia-1.0"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.0.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
================================================
FILE: .ipynb_checkpoints/Week 3_Peer graded quiz on Types-checkpoint.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Peer-graded quiz for `Types`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Please note that this notebook was created in Julia version 0.4.6."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Answer the following questions by creating the appropriate code."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 1\n",
"\n",
"List the subtypes of the `Real` type."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Subtypes of Real\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 2\n",
"\n",
"Create a user-defined type called `MyFloat` with a single field called `x` that is of type `Float64`."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a user-defined type called MyFloat with a single field called x of type Float64\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 3\n",
"\n",
"Instantiate the `MyFloat` type with a field values of $ 3 $."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Instantiate the MyFloat type with a field value of 3\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 4\n",
"\n",
"Create a user-defined parametrized type called `MyCube` with $ 3 $ fields called `h`, `w`, and `l`."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create a user-defined parametrized type called MyCube with $ 3 $ fields called h, w, and l.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 5\n",
"\n",
"Instantiate the type `MyCube` with $ 2 $ variables called `cube1` and `cube2`, i.e. `cube1 = MyCube(...`. Pass the field values $ 2 $, $ 3 $, and $ 2 $ to `cube1` and $ 4 $, $ 3 $, and $ 2 $ to `cube2`."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create 2 instances of the MyCube type\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 6\n",
"\n",
"Change the `h` field value of `cube1` to $ 3 $."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Change the h filed value of cube1 to 3\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 7\n",
"\n",
"Import the `Base.log` function."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Import the Base.log function\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 8\n",
"\n",
"Create and external constructor that will specify the `log()` function for an instance of the `MyCube` type as the natural logarithm of the product of the values held in the fields `h`, `w`, and `l`."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create and external constructor for the natural logarithm of the volume of an instance of MyCube\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 9\n",
"\n",
"Calculate the `log()` of `cube1`."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# The natural log of cube1\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 10\n",
"\n",
"Overload the methods of the `+()` function to add the individual field values of $ 2 $ instances of the `MyCube` type."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Overload the methods of the +() functions for the MyCube type\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 11\n",
"\n",
"Add `cube1` and `cube2`."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Add cube1 and cube2\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 0.4.6",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
================================================
FILE: .ipynb_checkpoints/Week 4_Peer graded quiz on Gadfly-checkpoint.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Peer-graded quiz on Gadfly"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Please note that this notebook was created in Julia version 0.4.6."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### After importing `Gadfly` and `DataFrames`, answer the following questions by creating the appropriate code."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# using Gadfly, DataFrames;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 1\n",
"\n",
"Create a DataFrame called `data` with column names `A`, `B`, `C`, and `D`. Each column should have $ 30 $ values.\n",
"\n",
"- For column `A` generate $ 30 $ random values in the range $ 1 : 10 $\n",
"- For column `B` generate $ 30 $ random values in the range $ 1 : 10 $\n",
"- For column `C` generate $ 30 $ random values from the choices `P` and `Q`\n",
"- For column `D` generate $ 30 $ random values from the choices `X`, `Y`, and `Z`"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create the DataFrame called data\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 2\n",
"\n",
"Create a scatter plot from columns `A` and `B` using the point geometry."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a scatter plot using the point geometry\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 3\n",
"\n",
"Change the point marker color to `gray` and increase the size to `5px`."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Change the point marker color to gray and the size to 5px\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 4\n",
"\n",
"Create a (simple) scatter plot using point geometry using values in columns `A` and `B`, but grouped by the unique elements found in column `C`. Leave all other elements at their default values."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a scatter plot using point geometry from the values in columns A and B, grouped by column C\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 5\n",
"\n",
"Receate the plot in *Question 4*, but change the point marker size to `10px`, with colors `#AAAAAA` and `#777777`."
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Recreate the plot in Question 4 with point marker size 10px and colors #AAAAAA and #777777\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 6\n",
"\n",
"Create a box plot of the values in column `A` based on the unique values in column `D`. Render the plot in `grey`."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a grey box plot of the values in column A based on the unique values in columns D\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 7\n",
"\n",
"Recreate the plot in Question 6. Increase the spacing to `50px` and add the plot title \"`My plot`\"."
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Recreate the plot in Question 6 with increased spacing (50px) and add the title My plot\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 8\n",
"\n",
"Recreate the plot in Question 7 but add a `ygroup` based on the unqiue values in column C."
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Recreate the plot in Question 7 but add a ygroup based on the unique values in column C\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 9\n",
"\n",
"Add a new column called `E` and add $ 30 $ values from the standard normal distribution."
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Add column E with 30 values form the standard normal distribution\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 10\n",
"\n",
"Create a density plot using the values in column `E` and draw a vertical line in `red` with size `2px` though the actual mean of the values in column `E`."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a density plot from the values in column E and draw a 2px red vertical line through the actual mean\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 0.4.6",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
================================================
FILE: .ipynb_checkpoints/Week 4_Peer graded quiz on data-checkpoint.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Peer-graded quiz for data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Please note that this notebook was created in Julia version 0.4.6."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Import the following packages and create the DataFrame as indicated."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: Method definition combinations(Any, Integer) in module Base at combinatorics.jl:182 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/combinations.jl:42.\n",
"WARNING: Method definition permutations(Any) in module Base at combinatorics.jl:219 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:24.\n",
"WARNING: Method definition partitions(Integer) in module Base at combinatorics.jl:252 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:26.\n",
"WARNING: Method definition partitions(Integer, Integer) in module Base at combinatorics.jl:318 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:93.\n",
"WARNING: Method definition partitions(AbstractArray{T<:Any, 1}) in module Base at combinatorics.jl:380 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:158.\n",
"WARNING: Method definition partitions(AbstractArray{T<:Any, 1}, Int64) in module Base at combinatorics.jl:447 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:228.\n",
"WARNING: Method definition factorial(#T<:Integer, #T<:Integer) in module Base at combinatorics.jl:56 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:18.\n",
"WARNING: Method definition factorial(Integer, Integer) in module Base at combinatorics.jl:66 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:28.\n",
"WARNING: Method definition parity(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:642 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:221.\n",
"WARNING: Method definition nthperm(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:92 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:161.\n",
"WARNING: Method definition nthperm(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:89 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:157.\n",
"WARNING: Method definition nthperm!(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:70 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:136.\n",
"WARNING: Method definition prevprod(Array{Int64, 1}, Any) in module Base at combinatorics.jl:565 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:354.\n",
"WARNING: Method definition levicivita(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:611 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:188.\n"
]
}
],
"source": [
"using DataFrames, Distributions, HypothesisTests;"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Plots.PlotlyJSBackend()"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Plots\n",
"plotlyjs()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: New definition \n",
" +(AbstractArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:106\n",
"is ambiguous with: \n",
" +(DataArrays.DataArray, AbstractArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:276.\n",
"To fix, define \n",
" +(DataArrays.DataArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury)\n",
"before the new definition.\n",
"WARNING: New definition \n",
" +(AbstractArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:106\n",
"is ambiguous with: \n",
" +(DataArrays.AbstractDataArray, AbstractArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:300.\n",
"To fix, define \n",
" +(DataArrays.AbstractDataArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury)\n",
"before the new definition.\n"
]
}
],
"source": [
"using StatPlots;"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data = DataFrame(Subject = collect(1:90), Age = rand(18:60, 90), Variable1 = rand(Normal(100, 10), 90),\n",
"Variable2 = rand(Chisq(5), 90), Variable3 = rand(Exponential(4), 90), Category1 = rand([\"X\", \"R\"], 90),\n",
"Category2 = rand([\"I\", \"II\", \"III\", \"IV\"], 90),\n",
"Category3 = rand([\"Improved\", \"Static\", \"Worsened\"], 90));"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Answer the following questions by creating the appropriate code."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 1\n",
"\n",
"Use the appropriate function from the `DataFrames` to describe the `Variable1` column."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Describe the values in Variable1\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 2\n",
"\n",
"Use the appropriate function from the `DataFrames` package to list how many unique values there are in the `Category1` column."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# How many unique value are there in the Category1 column?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 3\n",
"\n",
"Plot a histogram of the values in `Variable3` using 10 bins."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Histogram of Variable3\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 4\n",
"\n",
"Create two new DataFrames named `X` and `R` such that each of these sub-DataFrames only have the corresponding data point values in the `Category1` column, i.e. `X = ...`."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create three new sub-DataFrames based on the unique values in Category1\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 5\n",
"\n",
"Use the `EqualVarianceTTest()` from the `HypothesisTests` package to perform a *t*-test comparing the values in `Variable1` for the null hypothesis stating that there is no difference between the two groups."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# t-Test comparing Variable1 values between groups X and R\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 6\n",
"\n",
"Create a scatter plot for `Variable1` and `Variable2` values grouped by `Category1`. Make the title of the plot *My scatter plot*. The markers should be of opacity $ 0.5 $ and size $ 10 $."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Scatter plot of Variable1 against Variable2 grouped by Category1 with maker opacity 0.5 and size 10\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 7\n",
"\n",
"Create a sub-DataFrame called `worsened` including only rows indicating `Worsened` in the `Category3` column, i.e. `worsened = ...`."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a sub-DataFrame for patients that have worsened according to Category3 values\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 8\n",
"\n",
"Calculate the mean and standard deviation of `Variable1` values for patients who have `Worsened` as computer variables `meanw` and `stdw`, i.e. `meanw = ....`."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Mean of Variable1 for patients that have worsened\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 9\n",
"\n",
"Create a plot of the theoretical distribution using the values for `meanw` and `stdw`. State the `label` value as *Distribution* and provide a unique title to you plot."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Create a theoretical distribution plot with meanw and stdw\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Question 10\n",
"\n",
"Create a **Plotly** account and sign in. Return to your notebook and upload the image in *Question 10* to the **Plotly** cloud for editing. Save the plot by hitting the *Save* button. Share the link to the plot by copying the *share link* in a Markdown cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 0.4.6",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
================================================
FILE: .ipynb_checkpoints/Week3_Honors1-Types-checkpoint.ipynb
================================================
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,900,100italic,300italic,400italic,500italic,700italic,800italic,900italic' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=Arvo:400,700,400italic' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=PT+Mono' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=Philosopher:400,700,400italic,700italic' rel='stylesheet' type='text/css'>\n",
"\n",
"<style>\n",
"\n",
"@font-face {\n",
" font-family: \"Computer Modern\";\n",
" src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n",
"}\n",
"\n",
"#notebook_panel { /* main background */\n",
" background: #ddd;\n",
" color: #000000;\n",
"}\n",
"\n",
"\n",
"\n",
"/* Formatting for header cells */\n",
".text_cell_render h1 {\n",
" font-family: 'Philosopher', sans-serif;\n",
" font-weight: 400;\n",
" font-size: 2.2em;\n",
" line-height: 100%;\n",
" color: rgb(0, 80, 120);\n",
" margin-bottom: 0.1em;\n",
" margin-top: 0.1em;\n",
" display: block;\n",
"}\t\n",
".text_cell_render h2 {\n",
" font-family: 'Philosopher', serif;\n",
" font-weight: 400;\n",
" font-size: 1.9em;\n",
" line-height: 100%;\n",
" color: rgb(200,100,0);\n",
" margin-bottom: 0.1em;\n",
" margin-top: 0.1em;\n",
" display: block;\n",
"}\t\n",
"\n",
".text_cell_render h3 {\n",
" font-family: 'Philosopher', serif;\n",
" margin-top:12px;\n",
" margin-bottom: 3px;\n",
" font-style: italic;\n",
" color: rgb(94,127,192);\n",
"}\n",
"\n",
".text_cell_render h4 {\n",
" font-family: 'Philosopher', serif;\n",
"}\n",
"\n",
".text_cell_render h5 {\n",
" font-family: 'Alegreya Sans', sans-serif;\n",
" font-weight: 300;\n",
" font-size: 16pt;\n",
" color: grey;\n",
" font-style: italic;\n",
" margin-bottom: .1em;\n",
" margin-top: 0.1em;\n",
" display: block;\n",
"}\n",
"\n",
".text_cell_render h6 {\n",
" font-family: 'PT Mono', sans-serif;\n",
" font-weight: 300;\n",
" font-size: 10pt;\n",
" color: grey;\n",
" margin-bottom: 1px;\n",
" margin-top: 1px;\n",
"}\n",
"\n",
".CodeMirror{\n",
" font-family: \"PT Mono\";\n",
" font-size: 100%;\n",
"}\n",
"\n",
"</style>\n",
"\n"
],
"text/plain": [
"HTML{ASCIIString}(\"<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,900,100italic,300italic,400italic,500italic,700italic,800italic,900italic' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=Arvo:400,700,400italic' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=PT+Mono' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=Philosopher:400,700,400italic,700italic' rel='stylesheet' type='text/css'>\\n\\n<style>\\n\\n@font-face {\\n font-family: \\\"Computer Modern\\\";\\n src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\\n}\\n\\n#notebook_panel { /* main background */\\n background: #ddd;\\n color: #000000;\\n}\\n\\n\\n\\n/* Formatting for header cells */\\n.text_cell_render h1 {\\n font-family: 'Philosopher', sans-serif;\\n font-weight: 400;\\n font-size: 2.2em;\\n line-height: 100%;\\n color: rgb(0, 80, 120);\\n margin-bottom: 0.1em;\\n margin-top: 0.1em;\\n display: block;\\n}\\t\\n.text_cell_render h2 {\\n font-family: 'Philosopher', serif;\\n font-weight: 400;\\n font-size: 1.9em;\\n line-height: 100%;\\n color: rgb(200,100,0);\\n margin-bottom: 0.1em;\\n margin-top: 0.1em;\\n display: block;\\n}\\t\\n\\n.text_cell_render h3 {\\n font-family: 'Philosopher', serif;\\n margin-top:12px;\\n margin-bottom: 3px;\\n font-style: italic;\\n color: rgb(94,127,192);\\n}\\n\\n.text_cell_render h4 {\\n font-family: 'Philosopher', serif;\\n}\\n\\n.text_cell_render h5 {\\n font-family: 'Alegreya Sans', sans-serif;\\n font-weight: 300;\\n font-size: 16pt;\\n color: grey;\\n font-style: italic;\\n margin-bottom: .1em;\\n margin-top: 0.1em;\\n display: block;\\n}\\n\\n.text_cell_render h6 {\\n font-family: 'PT Mono', sans-serif;\\n font-weight: 300;\\n font-size: 10pt;\\n color: grey;\\n margin-bottom: 1px;\\n margin-top: 1px;\\n}\\n\\n.CodeMirror{\\n font-family: \\\"PT Mono\\\";\\n font-size: 100%;\\n}\\n\\n</style>\\n\\n\")"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Setting up a custom stylesheet in IJulia\n",
"file = open(\"style.css\") # A .css file in the same folder as this notebook file\n",
"styl = readall(file) # Read the file\n",
"HTML(\"$styl\") # Output as HTML"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Types"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>In this lesson</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- [Introduction](#Introduction)\n",
"- [Importing the packages for this lesson](#Importing-the-packages-for-this-lesson)\n",
"- [Outcomes](#Outcomes)\n",
"- [The type system in Julia](#The-type-system-in-Julia)\n",
"- [Type creation](#Type-creation)\n",
"- [Conversion and promotion](#Convertion-and-promotion)\n",
"- [Parametrizing a type](#Parametrizing-a-type)\n",
"- [The equality of values](#The-equality-of-values)\n",
"- [Defining methods for functions that will use user-types](#Defining-methods-for-functions-that-will-use-user-types)\n",
"- [Constraining field values](#Constraining-field-values)\n",
"- [More complex parameters](#More-complex-parameters)\n",
"- [Screen output of a user-defined type](#Screen-output-of-a-user-defined-type)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Introduction</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A computer variable, which is a space in memory, holds values of different types, i.e. integers, floating point values, and strings. In some languages the type of the value to be held inside of a variable must be explicitely declared. These languages are termed *statically typed*. In *dynamically typed* languages nothing is known about the type of the value held inside the variable until runtime. Being able to write code operating on different types is termed *polymorphism*."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Julia is a dynamically typed language, yet it is possible to declare a type for values as well. Declaring a type allows for code that is clear to understand. As an assertion it can help to confirm that your code is working as expected. It can also allow for faster code execution by providing the compiler with extra information."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Outcomes</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"After successfully completing this lecture, you will be able to:\n",
"\n",
"- Understand the Julia type system\n",
"- Create your own user-defined types\n",
"- Parametrize your types\n",
"- Overload methods for Julia functions so that they can use your types"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"<hr>\n",
"<h2>The type system in Julia</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Julia holds a type hierarchy that flows like the branches of a tree. Right at the top we have a type called `Any`. All types are subtypes of this type. Right at the final tip of the branches we have concrete types. They can hold values. Supertypes of these concrete types are called abtsract types and they cannot hold values, i.e. we cannot create an instance of an abstract type."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use Julia to see if types are subtypes of a supertype."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Is Number a subtype of Any?\n",
"Number <: Any"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Is Float 64 a subtype of AbstractFloat?\n",
"Float64 <: AbstractFloat"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"238-element Array{Any,1}:\n",
" AbstractArray{T,N} \n",
" AbstractChannel \n",
" AbstractRNG \n",
" AbstractString \n",
" Any \n",
" Associative{K,V} \n",
" Base.AbstractCmd \n",
" Base.AbstractMsg \n",
" Base.AbstractZipIterator \n",
" Base.Cartesian.LReplace{S<:AbstractString}\n",
" Base.Combinations{T} \n",
" Base.Count{S<:Number} \n",
" Base.Cycle{I} \n",
" ⋮ \n",
" TypeVar \n",
" Type{T} \n",
" UniformScaling{T<:Number} \n",
" Val{T} \n",
" Vararg{T} \n",
" VersionNumber \n",
" Void \n",
" WeakRef \n",
" WorkerConfig \n",
" ZMQ.Context \n",
" ZMQ.MsgPadding \n",
" ZMQ.Socket "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The subtypes of Any\n",
"subtypes(Any)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"8-element Array{Any,1}:\n",
" Base.SubstitutionString{T<:AbstractString}\n",
" DirectIndexString \n",
" RepString \n",
" RevString{T<:AbstractString} \n",
" RopeString \n",
" SubString{T<:AbstractString} \n",
" UTF16String \n",
" UTF8String "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Subtypes of AbstractString\n",
"subtypes(AbstractString)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Any,1}:\n",
" Complex{T<:Real}\n",
" Real "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Subtypes of Number\n",
"subtypes(Number)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Any,1}:\n",
" AbstractFloat \n",
" Integer \n",
" Irrational{sym} \n",
" Rational{T<:Integer}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Subtypes of Real\n",
"subtypes(Real)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Any,1}:\n",
" BigFloat\n",
" Float16 \n",
" Float32 \n",
" Float64 "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Subtypes of AbstractFloat\n",
"subtypes(AbstractFloat)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Any,1}:\n",
" BigInt \n",
" Bool \n",
" Signed \n",
" Unsigned"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Subtypes of Integer\n",
"subtypes(Integer)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"5-element Array{Any,1}:\n",
" Int128\n",
" Int16 \n",
" Int32 \n",
" Int64 \n",
" Int8 "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Subtypes of Signed\n",
"subtypes(Signed)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Declaring a type</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A type is declared by the double colon, `::`, sign. To the left we place the value (or placeholder for a variable, i.e. a variable name) and to the right the actual type. In the example below we want to express the fact that the value $ 2 + 2 $ is an instance of a 64-bit integer."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(2 + 2)::Int64"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we typed `(2 + 2)::Float64` we would get the following error:\n",
"```\n",
"LoadError: TypeError: typeassert: expected Float64, got Int64\n",
"while loading In[3], in expression starting on line 1\n",
"```\n",
"We used the declaration of a type as an assertion, which allowed us to see that there was something wrong with our code. We can imagine a program where the `+()` (or a more complicated user-defined) function is called and we need the arguments to be of a certain type. An error such as the one above can give us information about what went wrong."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Declaring a type of a local variable (inside of a function), we state that the type should always remain the same. This is more like what would happen in a statically typed language. It is really helpful if we want an error to be thrown should the type of a variable be changed by another part of our code. This can lead to type instability. It can really impact the speed of execution."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"static_local_variable (generic function with 1 method)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Creating a function with a local variable\n",
"function static_local_variable()\n",
" v::Int16 = 42\n",
" return v\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calling the function\n",
"static_local_variable()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Int16"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Checking the type of the answer just give\n",
"typeof(ans)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember that `v` is local to the function. If we try and look at it value by typing `v`, we would get the following error:\n",
"```\n",
"LoadError: UndefVarError: v not defined\n",
"while loading In[7], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that we know something about declaring a type, let's look at creating our own types."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Type creation</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As mentioned, we can create our own types. Consider a Cartesian coordinate system along two perpendicular axes, say $ x $ and $ y $. A vector in the plane can be represented as a type. The keyword we use to create a type is `type`. If we want instances of our type to be immutable, we use the keyword `immutable`."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Creating a concrete type called Vector_2D\n",
"type Vector_2D\n",
" x::Float64 # x is a fieldname of the type and has an optional type\n",
" y::Float64 # y is a fieldname of the type and has an optional type\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is actually a composite type, since we have fields. For a type that is non-composite we can imagine a simple wrapper around an already defined type, such as we do below."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# A non-composite type\n",
"type NonComposite\n",
" x::Float64\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"NonComposite(42.0)"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_non_composite = NonComposite(42)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"NonComposite"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Type\n",
"typeof(ans)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Back to the more exciting composite types. We can now instantiate the concrete type `Vector_2D`."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_2D(2.0,2.0)"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vector_1 = Vector_2D(2, 2)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_2D"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The type of vector_1\n",
"typeof(vector_1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice how we get floating point values even though we gave two integer values. The `convert()` functions was created to change allowable values to 64-bit floating point values."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Also notice that it looks like we called a function when we typed `Vector_2D(2, 2)`. When we define a type, constructors are created. They allow us to create an instance of that type (sometimes referred to as an *object* of that type)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As with functions, we can access the methods that were created with the type."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Any,1}:\n",
" call(::Type{Vector_2D}, x::Float64, y::Float64) at In[15]:3\n",
" call(::Type{Vector_2D}, x, y) at In[15]:3 \n",
" call{T}(::Type{T}, arg) at essentials.jl:56 \n",
" call{T}(::Type{T}, args...) at essentials.jl:57 "
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"methods(Vector_2D)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also access the fieldnames and their values. They are mutable, i.e. we can pass new values to them."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Symbol,1}:\n",
" :x\n",
" :y"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The available names (fields, fieldnames)\n",
"# Note that they are of type Symbol\n",
"fieldnames(Vector_2D)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Getting the value of the :x field\n",
"vector_1.x"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Alternative syntax using the field's symbol representation\n",
"getfield(vector_1, :x)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Another alternative notation using the index number of the fields\n",
"getfield(vector_1, 1)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3.0"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vector_1.x = 3"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_2D(3.0,2.0)"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vector_1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Another way to pass a value to a fieldname in a type is the `setfield()` function. We have to use the correct type for the value. If we use an integer such as `setfield!(vector_1, :x, 4)` we would get the follwoing error:\n",
"```\n",
"LoadError: TypeError: setfield!: expected Float64, got Int64\n",
"while loading In[25], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4.0"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now we have to use a floating point value\n",
"setfield!(vector_1, :x, 4.0)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_2D(4.0,2.0)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# vector_1 has been changed\n",
"vector_1"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Convertion and promotion</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before we go any further, we must have a look behind the scenes. Above we saw that an integer was converted to a floating point value as specified for the fields of our new type."
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"10.0"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using the convert function\n",
"convert(Float64, 10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If precision is lost, convertion will result in an error. For instance, `convert(Int16, 10.1)` will return:\n",
"```\n",
"adError: InexactError()\n",
"while loading In[20], in expression starting on line 1\n",
"```\n",
"Using `convert(Int16, 10.0)` will return a value of $ 10 $, though."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Julia has a type promotion system that will try to incorporate values into a single type. If we pass an integer and a floating point value, the integer will be promoted to a floating point value."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(10.0,10.0)"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"promote(10, 10.0)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Int64"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(10)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Float64"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(10.0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This promotion to a common type lifts the lid on multiple dispatch when a function is called with unspecified argument types (i.e. `Any`)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Parametrizing a type</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When creating a user type, we need not specify the type explicitely. We could use a parameter. Have a look at the example below."
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"type Vector_3D{T}\n",
" x::T\n",
" y::T\n",
" z::T\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We use $ T $ as a parameter placeholder. When we instantiate the type we can use any appropriate type, as long as all the fields values are of the same type."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_3D{Int64}(10,12,8)"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using 64 bit integers\n",
"vector_2 = Vector_3D(10, 12, 8)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we were to execute `vector_2 = Vector_3D(10.1, 10, 8)`, we would get the following error:\n",
"```\n",
"LoadError: MethodError: `convert` has no method matching convert(::Type{Vector_3D{T}}, ::Float64, ::Int64, ::Int64)\n",
"This may have arisen from a call to the constructor Vector_3D{T}(...),\n",
"since type constructors fall back to convert methods.\n",
"Closest candidates are:\n",
" Vector_3D{T}(::T, !Matched::T, !Matched::T)\n",
" call{T}(::Type{T}, ::Any)\n",
" convert{T}(::Type{T}, !Matched::T)\n",
"while loading In[28], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can constrain the parametric type. Below we allow all subtypes of of the abstract type `Real`."
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"type Vector_3D_Real{T <: Real}\n",
" x::T\n",
" y::T\n",
" z::T\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As an aside, we cannot redefine a type. If we would use:\n",
"```\n",
"type Vector_3D{T}\n",
" x::T\n",
" y::T\n",
" z::T\n",
"end\n",
"```\n",
"we would get the error:\n",
"```\n",
"LoadError: invalid redefinition of constant Vector_3D\n",
"while loading In[98], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_3D_Real{Int64}(3,3,3)"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Creating a new instance\n",
"vector_3 = Vector_3D_Real(3, 3, 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>The equality of values</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When are two values equal? We use a double equal sign to return a Boolean value."
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Using the functional notation\n",
"==(5, 5.0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Numbers are immutable and are compared at the bit level. This includes their types. We can use the `===` sign or the `is()` function to check for equality."
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"false"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is(5, 5.0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Where does this leave our user-defined types? We will see below that the address in memory is checked when dealing with more complex objects such as our user-defined, composite types."
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_2D(1.0,1.0)"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vector_a = Vector_2D(1.0, 1.0)\n",
"vector_b = Vector_2D(1.0, 1.0)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"false"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is(vector_a, vector_b)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Defining methods for functions that will use user-types</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The summation function, `+()` has methods for adding different types. What if we want to add two instances of our `Vector_2D` user-type? If we were to add `vector_a` to `vector_b` we would get the following error:\n",
"```\n",
"LoadError: MethodError: `+` has no method matching +(::Vector_2D, ::Vector_2D)\n",
"Closest candidates are:\n",
" +(::Any, ::Any, !Matched::Any, !Matched::Any...)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"171 methods for generic function <b>+</b>:<ul><li> +(x::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/bool.jl#L33\" target=\"_blank\">bool.jl:33</a><li> +(x::<b>Bool</b>, y::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/bool.jl#L36\" target=\"_blank\">bool.jl:36</a><li> +(y::<b>AbstractFloat</b>, x::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/bool.jl#L46\" target=\"_blank\">bool.jl:46</a><li> +(x::<b>Int64</b>, y::<b>Int64</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L8\" target=\"_blank\">int.jl:8</a><li> +(x::<b>Int8</b>, y::<b>Int8</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>UInt8</b>, y::<b>UInt8</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>Int16</b>, y::<b>Int16</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>UInt16</b>, y::<b>UInt16</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>Int32</b>, y::<b>Int32</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>UInt32</b>, y::<b>UInt32</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>UInt64</b>, y::<b>UInt64</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>Int128</b>, y::<b>Int128</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>UInt128</b>, y::<b>UInt128</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/int.jl#L16\" target=\"_blank\">int.jl:16</a><li> +(x::<b>Integer</b>, y::<b>Ptr{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/pointer.jl#L77\" target=\"_blank\">pointer.jl:77</a><li> +(x::<b>Float32</b>, y::<b>Float32</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/float.jl#L207\" target=\"_blank\">float.jl:207</a><li> +(x::<b>Float64</b>, y::<b>Float64</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/float.jl#L208\" target=\"_blank\">float.jl:208</a><li> +(z::<b>Complex{T<:Real}</b>, w::<b>Complex{T<:Real}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L111\" target=\"_blank\">complex.jl:111</a><li> +(x::<b>Bool</b>, z::<b>Complex{Bool}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L118\" target=\"_blank\">complex.jl:118</a><li> +(z::<b>Complex{Bool}</b>, x::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L119\" target=\"_blank\">complex.jl:119</a><li> +(x::<b>Bool</b>, z::<b>Complex{T<:Real}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L125\" target=\"_blank\">complex.jl:125</a><li> +(z::<b>Complex{T<:Real}</b>, x::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L126\" target=\"_blank\">complex.jl:126</a><li> +(x::<b>Real</b>, z::<b>Complex{Bool}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L132\" target=\"_blank\">complex.jl:132</a><li> +(z::<b>Complex{Bool}</b>, x::<b>Real</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L133\" target=\"_blank\">complex.jl:133</a><li> +(x::<b>Real</b>, z::<b>Complex{T<:Real}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L144\" target=\"_blank\">complex.jl:144</a><li> +(z::<b>Complex{T<:Real}</b>, x::<b>Real</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/complex.jl#L145\" target=\"_blank\">complex.jl:145</a><li> +(x::<b>Rational{T<:Integer}</b>, y::<b>Rational{T<:Integer}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/rational.jl#L179\" target=\"_blank\">rational.jl:179</a><li> +(x::<b>Bool</b>, A::<b>AbstractArray{Bool,N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L136\" target=\"_blank\">arraymath.jl:136</a><li> +(x::<b>Integer</b>, y::<b>Char</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/char.jl#L43\" target=\"_blank\">char.jl:43</a><li> +(a::<b>Float16</b>, b::<b>Float16</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/float16.jl#L136\" target=\"_blank\">float16.jl:136</a><li> +(x::<b>BigInt</b>, y::<b>BigInt</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L256\" target=\"_blank\">gmp.jl:256</a><li> +(a::<b>BigInt</b>, b::<b>BigInt</b>, c::<b>BigInt</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L279\" target=\"_blank\">gmp.jl:279</a><li> +(a::<b>BigInt</b>, b::<b>BigInt</b>, c::<b>BigInt</b>, d::<b>BigInt</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L285\" target=\"_blank\">gmp.jl:285</a><li> +(a::<b>BigInt</b>, b::<b>BigInt</b>, c::<b>BigInt</b>, d::<b>BigInt</b>, e::<b>BigInt</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L292\" target=\"_blank\">gmp.jl:292</a><li> +(x::<b>BigInt</b>, c::<b>Union{UInt16,UInt32,UInt64,UInt8}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L304\" target=\"_blank\">gmp.jl:304</a><li> +(c::<b>Union{UInt16,UInt32,UInt64,UInt8}</b>, x::<b>BigInt</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L308\" target=\"_blank\">gmp.jl:308</a><li> +(x::<b>BigInt</b>, c::<b>Union{Int16,Int32,Int64,Int8}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L320\" target=\"_blank\">gmp.jl:320</a><li> +(c::<b>Union{Int16,Int32,Int64,Int8}</b>, x::<b>BigInt</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/gmp.jl#L321\" target=\"_blank\">gmp.jl:321</a><li> +(x::<b>BigFloat</b>, y::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L208\" target=\"_blank\">mpfr.jl:208</a><li> +(x::<b>BigFloat</b>, c::<b>Union{UInt16,UInt32,UInt64,UInt8}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L215\" target=\"_blank\">mpfr.jl:215</a><li> +(c::<b>Union{UInt16,UInt32,UInt64,UInt8}</b>, x::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L219\" target=\"_blank\">mpfr.jl:219</a><li> +(x::<b>BigFloat</b>, c::<b>Union{Int16,Int32,Int64,Int8}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L223\" target=\"_blank\">mpfr.jl:223</a><li> +(c::<b>Union{Int16,Int32,Int64,Int8}</b>, x::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L227\" target=\"_blank\">mpfr.jl:227</a><li> +(x::<b>BigFloat</b>, c::<b>Union{Float16,Float32,Float64}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L231\" target=\"_blank\">mpfr.jl:231</a><li> +(c::<b>Union{Float16,Float32,Float64}</b>, x::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L235\" target=\"_blank\">mpfr.jl:235</a><li> +(x::<b>BigFloat</b>, c::<b>BigInt</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L239\" target=\"_blank\">mpfr.jl:239</a><li> +(c::<b>BigInt</b>, x::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L243\" target=\"_blank\">mpfr.jl:243</a><li> +(a::<b>BigFloat</b>, b::<b>BigFloat</b>, c::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L379\" target=\"_blank\">mpfr.jl:379</a><li> +(a::<b>BigFloat</b>, b::<b>BigFloat</b>, c::<b>BigFloat</b>, d::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L385\" target=\"_blank\">mpfr.jl:385</a><li> +(a::<b>BigFloat</b>, b::<b>BigFloat</b>, c::<b>BigFloat</b>, d::<b>BigFloat</b>, e::<b>BigFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/mpfr.jl#L392\" target=\"_blank\">mpfr.jl:392</a><li> +(x::<b>Irrational{sym}</b>, y::<b>Irrational{sym}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/irrationals.jl#L72\" target=\"_blank\">irrationals.jl:72</a><li> +(x::<b>Number</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/operators.jl#L73\" target=\"_blank\">operators.jl:73</a><li> +<i>{T<:Number}</i>(x::<b>T<:Number</b>, y::<b>T<:Number</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/promotion.jl#L211\" target=\"_blank\">promotion.jl:211</a><li> +<i>{T<:AbstractFloat}</i>(x::<b>Bool</b>, y::<b>T<:AbstractFloat</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/bool.jl#L43\" target=\"_blank\">bool.jl:43</a><li> +(x::<b>Number</b>, y::<b>Number</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/promotion.jl#L167\" target=\"_blank\">promotion.jl:167</a><li> +(r1::<b>OrdinalRange{T,S}</b>, r2::<b>OrdinalRange{T,S}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/operators.jl#L330\" target=\"_blank\">operators.jl:330</a><li> +<i>{T<:AbstractFloat}</i>(r1::<b>FloatRange{T<:AbstractFloat}</b>, r2::<b>FloatRange{T<:AbstractFloat}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/operators.jl#L337\" target=\"_blank\">operators.jl:337</a><li> +<i>{T<:AbstractFloat}</i>(r1::<b>LinSpace{T<:AbstractFloat}</b>, r2::<b>LinSpace{T<:AbstractFloat}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/operators.jl#L356\" target=\"_blank\">operators.jl:356</a><li> +(r1::<b>Union{FloatRange{T<:AbstractFloat},LinSpace{T<:AbstractFloat},OrdinalRange{T,S}}</b>, r2::<b>Union{FloatRange{T<:AbstractFloat},LinSpace{T<:AbstractFloat},OrdinalRange{T,S}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/operators.jl#L369\" target=\"_blank\">operators.jl:369</a><li> +(x::<b>Ptr{T}</b>, y::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/pointer.jl#L75\" target=\"_blank\">pointer.jl:75</a><li> +<i>{S,T}</i>(A::<b>Range{S}</b>, B::<b>Range{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L69\" target=\"_blank\">arraymath.jl:69</a><li> +<i>{S,T}</i>(A::<b>Range{S}</b>, B::<b>AbstractArray{T,N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L87\" target=\"_blank\">arraymath.jl:87</a><li> +(A::<b>BitArray{N}</b>, B::<b>BitArray{N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/bitarray.jl#L859\" target=\"_blank\">bitarray.jl:859</a><li> +<i>{T}</i>(B::<b>BitArray{2}</b>, J::<b>UniformScaling{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L28\" target=\"_blank\">linalg/uniformscaling.jl:28</a><li> +(A::<b>Array{T,2}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L122\" target=\"_blank\">linalg/special.jl:122</a><li> +(A::<b>Array{T,2}</b>, B::<b>Bidiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L122\" target=\"_blank\">linalg/special.jl:122</a><li> +(A::<b>Array{T,2}</b>, B::<b>Tridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L122\" target=\"_blank\">linalg/special.jl:122</a><li> +(A::<b>Array{T,2}</b>, B::<b>SymTridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L131\" target=\"_blank\">linalg/special.jl:131</a><li> +(A::<b>Array{T,2}</b>, B::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L159\" target=\"_blank\">linalg/special.jl:159</a><li> +(A::<b>Array{T,N}</b>, B::<b>SparseMatrixCSC{Tv,Ti<:Integer}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/sparse/sparsematrix.jl#L1019\" target=\"_blank\">sparse/sparsematrix.jl:1019</a><li> +<i>{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}</i>(x::<b>Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L221\" target=\"_blank\">dates/periods.jl:221</a><li> +(A::<b>AbstractArray{Bool,N}</b>, x::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L135\" target=\"_blank\">arraymath.jl:135</a><li> +(A::<b>Union{DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>, B::<b>Union{DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L166\" target=\"_blank\">arraymath.jl:166</a><li> +(A::<b>SymTridiagonal{T}</b>, B::<b>SymTridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/tridiag.jl#L84\" target=\"_blank\">linalg/tridiag.jl:84</a><li> +(A::<b>Tridiagonal{T}</b>, B::<b>Tridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/tridiag.jl#L404\" target=\"_blank\">linalg/tridiag.jl:404</a><li> +(A::<b>UpperTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>UpperTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L347\" target=\"_blank\">linalg/triangular.jl:347</a><li> +(A::<b>LowerTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>LowerTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L348\" target=\"_blank\">linalg/triangular.jl:348</a><li> +(A::<b>UpperTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L349\" target=\"_blank\">linalg/triangular.jl:349</a><li> +(A::<b>LowerTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L350\" target=\"_blank\">linalg/triangular.jl:350</a><li> +(A::<b>Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>UpperTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L351\" target=\"_blank\">linalg/triangular.jl:351</a><li> +(A::<b>Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>LowerTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L352\" target=\"_blank\">linalg/triangular.jl:352</a><li> +(A::<b>Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L353\" target=\"_blank\">linalg/triangular.jl:353</a><li> +(A::<b>Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L354\" target=\"_blank\">linalg/triangular.jl:354</a><li> +(A::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/triangular.jl#L355\" target=\"_blank\">linalg/triangular.jl:355</a><li> +(Da::<b>Diagonal{T}</b>, Db::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/diagonal.jl#L86\" target=\"_blank\">linalg/diagonal.jl:86</a><li> +(A::<b>Bidiagonal{T}</b>, B::<b>Bidiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/bidiag.jl#L176\" target=\"_blank\">linalg/bidiag.jl:176</a><li> +(UL::<b>UpperTriangular{T,S<:AbstractArray{T,2}}</b>, J::<b>UniformScaling{T<:Number}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L45\" target=\"_blank\">linalg/uniformscaling.jl:45</a><li> +(UL::<b>Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}</b>, J::<b>UniformScaling{T<:Number}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L48\" target=\"_blank\">linalg/uniformscaling.jl:48</a><li> +(UL::<b>LowerTriangular{T,S<:AbstractArray{T,2}}</b>, J::<b>UniformScaling{T<:Number}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L45\" target=\"_blank\">linalg/uniformscaling.jl:45</a><li> +(UL::<b>Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}</b>, J::<b>UniformScaling{T<:Number}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L48\" target=\"_blank\">linalg/uniformscaling.jl:48</a><li> +(A::<b>Diagonal{T}</b>, B::<b>Bidiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L121\" target=\"_blank\">linalg/special.jl:121</a><li> +(A::<b>Bidiagonal{T}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L122\" target=\"_blank\">linalg/special.jl:122</a><li> +(A::<b>Diagonal{T}</b>, B::<b>Tridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L121\" target=\"_blank\">linalg/special.jl:121</a><li> +(A::<b>Tridiagonal{T}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L122\" target=\"_blank\">linalg/special.jl:122</a><li> +(A::<b>Diagonal{T}</b>, B::<b>Array{T,2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L121\" target=\"_blank\">linalg/special.jl:121</a><li> +(A::<b>Bidiagonal{T}</b>, B::<b>Tridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L121\" target=\"_blank\">linalg/special.jl:121</a><li> +(A::<b>Tridiagonal{T}</b>, B::<b>Bidiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L122\" target=\"_blank\">linalg/special.jl:122</a><li> +(A::<b>Bidiagonal{T}</b>, B::<b>Array{T,2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L121\" target=\"_blank\">linalg/special.jl:121</a><li> +(A::<b>Tridiagonal{T}</b>, B::<b>Array{T,2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L121\" target=\"_blank\">linalg/special.jl:121</a><li> +(A::<b>SymTridiagonal{T}</b>, B::<b>Tridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L130\" target=\"_blank\">linalg/special.jl:130</a><li> +(A::<b>Tridiagonal{T}</b>, B::<b>SymTridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L131\" target=\"_blank\">linalg/special.jl:131</a><li> +(A::<b>SymTridiagonal{T}</b>, B::<b>Array{T,2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L130\" target=\"_blank\">linalg/special.jl:130</a><li> +(A::<b>Diagonal{T}</b>, B::<b>SymTridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L139\" target=\"_blank\">linalg/special.jl:139</a><li> +(A::<b>SymTridiagonal{T}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L140\" target=\"_blank\">linalg/special.jl:140</a><li> +(A::<b>Bidiagonal{T}</b>, B::<b>SymTridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L139\" target=\"_blank\">linalg/special.jl:139</a><li> +(A::<b>SymTridiagonal{T}</b>, B::<b>Bidiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L140\" target=\"_blank\">linalg/special.jl:140</a><li> +(A::<b>Diagonal{T}</b>, B::<b>UpperTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L151\" target=\"_blank\">linalg/special.jl:151</a><li> +(A::<b>UpperTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L152\" target=\"_blank\">linalg/special.jl:152</a><li> +(A::<b>Diagonal{T}</b>, B::<b>Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L151\" target=\"_blank\">linalg/special.jl:151</a><li> +(A::<b>Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L152\" target=\"_blank\">linalg/special.jl:152</a><li> +(A::<b>Diagonal{T}</b>, B::<b>LowerTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L151\" target=\"_blank\">linalg/special.jl:151</a><li> +(A::<b>LowerTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L152\" target=\"_blank\">linalg/special.jl:152</a><li> +(A::<b>Diagonal{T}</b>, B::<b>Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L151\" target=\"_blank\">linalg/special.jl:151</a><li> +(A::<b>Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Diagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L152\" target=\"_blank\">linalg/special.jl:152</a><li> +(A::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>SymTridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L158\" target=\"_blank\">linalg/special.jl:158</a><li> +(A::<b>SymTridiagonal{T}</b>, B::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L159\" target=\"_blank\">linalg/special.jl:159</a><li> +(A::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Tridiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L158\" target=\"_blank\">linalg/special.jl:158</a><li> +(A::<b>Tridiagonal{T}</b>, B::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L159\" target=\"_blank\">linalg/special.jl:159</a><li> +(A::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Bidiagonal{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L158\" target=\"_blank\">linalg/special.jl:158</a><li> +(A::<b>Bidiagonal{T}</b>, B::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L159\" target=\"_blank\">linalg/special.jl:159</a><li> +(A::<b>Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}</b>, B::<b>Array{T,2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/special.jl#L158\" target=\"_blank\">linalg/special.jl:158</a><li> +<i>{Tv1,Ti1,Tv2,Ti2}</i>(A_1::<b>SparseMatrixCSC{Tv1,Ti1}</b>, A_2::<b>SparseMatrixCSC{Tv2,Ti2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/sparse/sparsematrix.jl#L1005\" target=\"_blank\">sparse/sparsematrix.jl:1005</a><li> +(A::<b>SparseMatrixCSC{Tv,Ti<:Integer}</b>, B::<b>Array{T,N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/sparse/sparsematrix.jl#L1017\" target=\"_blank\">sparse/sparsematrix.jl:1017</a><li> +(A::<b>SparseMatrixCSC{Tv,Ti<:Integer}</b>, J::<b>UniformScaling{T<:Number}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/sparse/sparsematrix.jl#L3030\" target=\"_blank\">sparse/sparsematrix.jl:3030</a><li> +<i>{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}</i>(Y::<b>Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>, x::<b>Union{Base.Dates.CompoundPeriod,Base.Dates.Period}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L235\" target=\"_blank\">dates/periods.jl:235</a><li> +<i>{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},Q<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}</i>(X::<b>Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>, Y::<b>Union{DenseArray{Q<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{Q<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L236\" target=\"_blank\">dates/periods.jl:236</a><li> +<i>{T<:Base.Dates.TimeType,P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}</i>(x::<b>Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>, y::<b>T<:Base.Dates.TimeType</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L83\" target=\"_blank\">dates/arithmetic.jl:83</a><li> +<i>{T<:Base.Dates.TimeType}</i>(r::<b>Range{T<:Base.Dates.TimeType}</b>, x::<b>Base.Dates.Period</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/ranges.jl#L39\" target=\"_blank\">dates/ranges.jl:39</a><li> +<i>{T<:Number}</i>(x::<b>AbstractArray{T<:Number,N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/abstractarraymath.jl#L49\" target=\"_blank\">abstractarraymath.jl:49</a><li> +<i>{S,T}</i>(A::<b>AbstractArray{S,N}</b>, B::<b>Range{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L78\" target=\"_blank\">arraymath.jl:78</a><li> +<i>{S,T}</i>(A::<b>AbstractArray{S,N}</b>, B::<b>AbstractArray{T,N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L96\" target=\"_blank\">arraymath.jl:96</a><li> +(A::<b>AbstractArray{T,N}</b>, x::<b>Number</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L139\" target=\"_blank\">arraymath.jl:139</a><li> +(x::<b>Number</b>, A::<b>AbstractArray{T,N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/arraymath.jl#L140\" target=\"_blank\">arraymath.jl:140</a><li> +(x::<b>Char</b>, y::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/char.jl#L42\" target=\"_blank\">char.jl:42</a><li> +<i>{N}</i>(index1::<b>CartesianIndex{N}</b>, index2::<b>CartesianIndex{N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/multidimensional.jl#L42\" target=\"_blank\">multidimensional.jl:42</a><li> +(J1::<b>UniformScaling{T<:Number}</b>, J2::<b>UniformScaling{T<:Number}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L27\" target=\"_blank\">linalg/uniformscaling.jl:27</a><li> +(J::<b>UniformScaling{T<:Number}</b>, B::<b>BitArray{2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L29\" target=\"_blank\">linalg/uniformscaling.jl:29</a><li> +(J::<b>UniformScaling{T<:Number}</b>, A::<b>AbstractArray{T,2}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L30\" target=\"_blank\">linalg/uniformscaling.jl:30</a><li> +(J::<b>UniformScaling{T<:Number}</b>, x::<b>Number</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L31\" target=\"_blank\">linalg/uniformscaling.jl:31</a><li> +(x::<b>Number</b>, J::<b>UniformScaling{T<:Number}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L32\" target=\"_blank\">linalg/uniformscaling.jl:32</a><li> +<i>{TA,TJ}</i>(A::<b>AbstractArray{TA,2}</b>, J::<b>UniformScaling{TJ}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/linalg/uniformscaling.jl#L92\" target=\"_blank\">linalg/uniformscaling.jl:92</a><li> +<i>{T}</i>(a::<b>Base.Pkg.Resolve.VersionWeights.HierarchicalValue{T}</b>, b::<b>Base.Pkg.Resolve.VersionWeights.HierarchicalValue{T}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/pkg/resolve/versionweight.jl#L23\" target=\"_blank\">pkg/resolve/versionweight.jl:23</a><li> +(a::<b>Base.Pkg.Resolve.VersionWeights.VWPreBuildItem</b>, b::<b>Base.Pkg.Resolve.VersionWeights.VWPreBuildItem</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/pkg/resolve/versionweight.jl#L85\" target=\"_blank\">pkg/resolve/versionweight.jl:85</a><li> +(a::<b>Base.Pkg.Resolve.VersionWeights.VWPreBuild</b>, b::<b>Base.Pkg.Resolve.VersionWeights.VWPreBuild</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/pkg/resolve/versionweight.jl#L131\" target=\"_blank\">pkg/resolve/versionweight.jl:131</a><li> +(a::<b>Base.Pkg.Resolve.VersionWeights.VersionWeight</b>, b::<b>Base.Pkg.Resolve.VersionWeights.VersionWeight</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/pkg/resolve/versionweight.jl#L185\" target=\"_blank\">pkg/resolve/versionweight.jl:185</a><li> +(a::<b>Base.Pkg.Resolve.MaxSum.FieldValues.FieldValue</b>, b::<b>Base.Pkg.Resolve.MaxSum.FieldValues.FieldValue</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/pkg/resolve/fieldvalue.jl#L44\" target=\"_blank\">pkg/resolve/fieldvalue.jl:44</a><li> +<i>{P<:Base.Dates.Period}</i>(x::<b>P<:Base.Dates.Period</b>, y::<b>P<:Base.Dates.Period</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L62\" target=\"_blank\">dates/periods.jl:62</a><li> +(x::<b>Base.Dates.Period</b>, y::<b>Base.Dates.Period</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L209\" target=\"_blank\">dates/periods.jl:209</a><li> +(x::<b>Base.Dates.CompoundPeriod</b>, y::<b>Base.Dates.Period</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L210\" target=\"_blank\">dates/periods.jl:210</a><li> +(y::<b>Base.Dates.Period</b>, x::<b>Base.Dates.CompoundPeriod</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L211\" target=\"_blank\">dates/periods.jl:211</a><li> +(x::<b>Base.Dates.CompoundPeriod</b>, y::<b>Base.Dates.CompoundPeriod</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L212\" target=\"_blank\">dates/periods.jl:212</a><li> +(x::<b>Base.Dates.CompoundPeriod</b>, y::<b>Base.Dates.TimeType</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L257\" target=\"_blank\">dates/periods.jl:257</a><li> +(y::<b>Base.Dates.Period</b>, x::<b>Base.Dates.TimeType</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L66\" target=\"_blank\">dates/arithmetic.jl:66</a><li> +<i>{T<:Base.Dates.TimeType}</i>(x::<b>Base.Dates.Period</b>, r::<b>Range{T<:Base.Dates.TimeType}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/ranges.jl#L40\" target=\"_blank\">dates/ranges.jl:40</a><li> +(x::<b>Union{Base.Dates.CompoundPeriod,Base.Dates.Period}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L220\" target=\"_blank\">dates/periods.jl:220</a><li> +<i>{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}</i>(x::<b>Union{Base.Dates.CompoundPeriod,Base.Dates.Period}</b>, Y::<b>Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L234\" target=\"_blank\">dates/periods.jl:234</a><li> +(dt::<b>DateTime</b>, y::<b>Base.Dates.Year</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L13\" target=\"_blank\">dates/arithmetic.jl:13</a><li> +(dt::<b>Date</b>, y::<b>Base.Dates.Year</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L17\" target=\"_blank\">dates/arithmetic.jl:17</a><li> +(dt::<b>DateTime</b>, z::<b>Base.Dates.Month</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L37\" target=\"_blank\">dates/arithmetic.jl:37</a><li> +(dt::<b>Date</b>, z::<b>Base.Dates.Month</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L43\" target=\"_blank\">dates/arithmetic.jl:43</a><li> +(x::<b>Date</b>, y::<b>Base.Dates.Week</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L60\" target=\"_blank\">dates/arithmetic.jl:60</a><li> +(x::<b>Date</b>, y::<b>Base.Dates.Day</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L62\" target=\"_blank\">dates/arithmetic.jl:62</a><li> +(x::<b>DateTime</b>, y::<b>Base.Dates.Period</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L64\" target=\"_blank\">dates/arithmetic.jl:64</a><li> +(x::<b>Base.Dates.TimeType</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L8\" target=\"_blank\">dates/arithmetic.jl:8</a><li> +(a::<b>Base.Dates.TimeType</b>, b::<b>Base.Dates.Period</b>, c::<b>Base.Dates.Period</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L246\" target=\"_blank\">dates/periods.jl:246</a><li> +(a::<b>Base.Dates.TimeType</b>, b::<b>Base.Dates.Period</b>, c::<b>Base.Dates.Period</b>, d::<b>Base.Dates.Period...</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L248\" target=\"_blank\">dates/periods.jl:248</a><li> +(x::<b>Base.Dates.TimeType</b>, y::<b>Base.Dates.CompoundPeriod</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/periods.jl#L252\" target=\"_blank\">dates/periods.jl:252</a><li> +(x::<b>Base.Dates.Instant</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L4\" target=\"_blank\">dates/arithmetic.jl:4</a><li> +<i>{T<:Base.Dates.TimeType}</i>(x::<b>AbstractArray{T<:Base.Dates.TimeType,N}</b>, y::<b>Union{Base.Dates.CompoundPeriod,Base.Dates.Period}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L76\" target=\"_blank\">dates/arithmetic.jl:76</a><li> +<i>{T<:Base.Dates.TimeType}</i>(y::<b>Union{Base.Dates.CompoundPeriod,Base.Dates.Period}</b>, x::<b>AbstractArray{T<:Base.Dates.TimeType,N}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L77\" target=\"_blank\">dates/arithmetic.jl:77</a><li> +<i>{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}</i>(y::<b>Base.Dates.TimeType</b>, x::<b>Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/dates/arithmetic.jl#L84\" target=\"_blank\">dates/arithmetic.jl:84</a><li> +(a, b, c, xs...) at <a href=\"https://github.com/JuliaLang/julia/tree/2e358ce975029ec97aba5994c17d4a2169c3b085/base/operators.jl#L103\" target=\"_blank\">operators.jl:103</a></ul>"
],
"text/plain": [
"# 171 methods for generic function \"+\":\n",
"+(x::Bool) at bool.jl:33\n",
"+(x::Bool, y::Bool) at bool.jl:36\n",
"+(y::AbstractFloat, x::Bool) at bool.jl:46\n",
"+(x::Int64, y::Int64) at int.jl:8\n",
"+(x::Int8, y::Int8) at int.jl:16\n",
"+(x::UInt8, y::UInt8) at int.jl:16\n",
"+(x::Int16, y::Int16) at int.jl:16\n",
"+(x::UInt16, y::UInt16) at int.jl:16\n",
"+(x::Int32, y::Int32) at int.jl:16\n",
"+(x::UInt32, y::UInt32) at int.jl:16\n",
"+(x::UInt64, y::UInt64) at int.jl:16\n",
"+(x::Int128, y::Int128) at int.jl:16\n",
"+(x::UInt128, y::UInt128) at int.jl:16\n",
"+(x::Integer, y::Ptr{T}) at pointer.jl:77\n",
"+(x::Float32, y::Float32) at float.jl:207\n",
"+(x::Float64, y::Float64) at float.jl:208\n",
"+(z::Complex{T<:Real}, w::Complex{T<:Real}) at complex.jl:111\n",
"+(x::Bool, z::Complex{Bool}) at complex.jl:118\n",
"+(z::Complex{Bool}, x::Bool) at complex.jl:119\n",
"+(x::Bool, z::Complex{T<:Real}) at complex.jl:125\n",
"+(z::Complex{T<:Real}, x::Bool) at complex.jl:126\n",
"+(x::Real, z::Complex{Bool}) at complex.jl:132\n",
"+(z::Complex{Bool}, x::Real) at complex.jl:133\n",
"+(x::Real, z::Complex{T<:Real}) at complex.jl:144\n",
"+(z::Complex{T<:Real}, x::Real) at complex.jl:145\n",
"+(x::Rational{T<:Integer}, y::Rational{T<:Integer}) at rational.jl:179\n",
"+(x::Bool, A::AbstractArray{Bool,N}) at arraymath.jl:136\n",
"+(x::Integer, y::Char) at char.jl:43\n",
"+(a::Float16, b::Float16) at float16.jl:136\n",
"+(x::BigInt, y::BigInt) at gmp.jl:256\n",
"+(a::BigInt, b::BigInt, c::BigInt) at gmp.jl:279\n",
"+(a::BigInt, b::BigInt, c::BigInt, d::BigInt) at gmp.jl:285\n",
"+(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) at gmp.jl:292\n",
"+(x::BigInt, c::Union{UInt16,UInt32,UInt64,UInt8}) at gmp.jl:304\n",
"+(c::Union{UInt16,UInt32,UInt64,UInt8}, x::BigInt) at gmp.jl:308\n",
"+(x::BigInt, c::Union{Int16,Int32,Int64,Int8}) at gmp.jl:320\n",
"+(c::Union{Int16,Int32,Int64,Int8}, x::BigInt) at gmp.jl:321\n",
"+(x::BigFloat, y::BigFloat) at mpfr.jl:208\n",
"+(x::BigFloat, c::Union{UInt16,UInt32,UInt64,UInt8}) at mpfr.jl:215\n",
"+(c::Union{UInt16,UInt32,UInt64,UInt8}, x::BigFloat) at mpfr.jl:219\n",
"+(x::BigFloat, c::Union{Int16,Int32,Int64,Int8}) at mpfr.jl:223\n",
"+(c::Union{Int16,Int32,Int64,Int8}, x::BigFloat) at mpfr.jl:227\n",
"+(x::BigFloat, c::Union{Float16,Float32,Float64}) at mpfr.jl:231\n",
"+(c::Union{Float16,Float32,Float64}, x::BigFloat) at mpfr.jl:235\n",
"+(x::BigFloat, c::BigInt) at mpfr.jl:239\n",
"+(c::BigInt, x::BigFloat) at mpfr.jl:243\n",
"+(a::BigFloat, b::BigFloat, c::BigFloat) at mpfr.jl:379\n",
"+(a::BigFloat, b::BigFloat, c::BigFloat, d::BigFloat) at mpfr.jl:385\n",
"+(a::BigFloat, b::BigFloat, c::BigFloat, d::BigFloat, e::BigFloat) at mpfr.jl:392\n",
"+(x::Irrational{sym}, y::Irrational{sym}) at irrationals.jl:72\n",
"+(x::Number) at operators.jl:73\n",
"+{T<:Number}(x::T<:Number, y::T<:Number) at promotion.jl:211\n",
"+{T<:AbstractFloat}(x::Bool, y::T<:AbstractFloat) at bool.jl:43\n",
"+(x::Number, y::Number) at promotion.jl:167\n",
"+(r1::OrdinalRange{T,S}, r2::OrdinalRange{T,S}) at operators.jl:330\n",
"+{T<:AbstractFloat}(r1::FloatRange{T<:AbstractFloat}, r2::FloatRange{T<:AbstractFloat}) at operators.jl:337\n",
"+{T<:AbstractFloat}(r1::LinSpace{T<:AbstractFloat}, r2::LinSpace{T<:AbstractFloat}) at operators.jl:356\n",
"+(r1::Union{FloatRange{T<:AbstractFloat},LinSpace{T<:AbstractFloat},OrdinalRange{T,S}}, r2::Union{FloatRange{T<:AbstractFloat},LinSpace{T<:AbstractFloat},OrdinalRange{T,S}}) at operators.jl:369\n",
"+(x::Ptr{T}, y::Integer) at pointer.jl:75\n",
"+{S,T}(A::Range{S}, B::Range{T}) at arraymath.jl:69\n",
"+{S,T}(A::Range{S}, B::AbstractArray{T,N}) at arraymath.jl:87\n",
"+(A::BitArray{N}, B::BitArray{N}) at bitarray.jl:859\n",
"+{T}(B::BitArray{2}, J::UniformScaling{T}) at linalg/uniformscaling.jl:28\n",
"+(A::Array{T,2}, B::Diagonal{T}) at linalg/special.jl:122\n",
"+(A::Array{T,2}, B::Bidiagonal{T}) at linalg/special.jl:122\n",
"+(A::Array{T,2}, B::Tridiagonal{T}) at linalg/special.jl:122\n",
"+(A::Array{T,2}, B::SymTridiagonal{T}) at linalg/special.jl:131\n",
"+(A::Array{T,2}, B::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:159\n",
"+(A::Array{T,N}, B::SparseMatrixCSC{Tv,Ti<:Integer}) at sparse/sparsematrix.jl:1019\n",
"+{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}(x::Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}) at dates/periods.jl:221\n",
"+(A::AbstractArray{Bool,N}, x::Bool) at arraymath.jl:135\n",
"+(A::Union{DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}, B::Union{DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}) at arraymath.jl:166\n",
"+(A::SymTridiagonal{T}, B::SymTridiagonal{T}) at linalg/tridiag.jl:84\n",
"+(A::Tridiagonal{T}, B::Tridiagonal{T}) at linalg/tridiag.jl:404\n",
"+(A::UpperTriangular{T,S<:AbstractArray{T,2}}, B::UpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:347\n",
"+(A::LowerTriangular{T,S<:AbstractArray{T,2}}, B::LowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:348\n",
"+(A::UpperTriangular{T,S<:AbstractArray{T,2}}, B::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:349\n",
"+(A::LowerTriangular{T,S<:AbstractArray{T,2}}, B::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:350\n",
"+(A::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}, B::UpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:351\n",
"+(A::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}, B::LowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:352\n",
"+(A::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}, B::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:353\n",
"+(A::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}, B::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:354\n",
"+(A::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}, B::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:355\n",
"+(Da::Diagonal{T}, Db::Diagonal{T}) at linalg/diagonal.jl:86\n",
"+(A::Bidiagonal{T}, B::Bidiagonal{T}) at linalg/bidiag.jl:176\n",
"+(UL::UpperTriangular{T,S<:AbstractArray{T,2}}, J::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:45\n",
"+(UL::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}, J::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:48\n",
"+(UL::LowerTriangular{T,S<:AbstractArray{T,2}}, J::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:45\n",
"+(UL::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}, J::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:48\n",
"+(A::Diagonal{T}, B::Bidiagonal{T}) at linalg/special.jl:121\n",
"+(A::Bidiagonal{T}, B::Diagonal{T}) at linalg/special.jl:122\n",
"+(A::Diagonal{T}, B::Tridiagonal{T}) at linalg/special.jl:121\n",
"+(A::Tridiagonal{T}, B::Diagonal{T}) at linalg/special.jl:122\n",
"+(A::Diagonal{T}, B::Array{T,2}) at linalg/special.jl:121\n",
"+(A::Bidiagonal{T}, B::Tridiagonal{T}) at linalg/special.jl:121\n",
"+(A::Tridiagonal{T}, B::Bidiagonal{T}) at linalg/special.jl:122\n",
"+(A::Bidiagonal{T}, B::Array{T,2}) at linalg/special.jl:121\n",
"+(A::Tridiagonal{T}, B::Array{T,2}) at linalg/special.jl:121\n",
"+(A::SymTridiagonal{T}, B::Tridiagonal{T}) at linalg/special.jl:130\n",
"+(A::Tridiagonal{T}, B::SymTridiagonal{T}) at linalg/special.jl:131\n",
"+(A::SymTridiagonal{T}, B::Array{T,2}) at linalg/special.jl:130\n",
"+(A::Diagonal{T}, B::SymTridiagonal{T}) at linalg/special.jl:139\n",
"+(A::SymTridiagonal{T}, B::Diagonal{T}) at linalg/special.jl:140\n",
"+(A::Bidiagonal{T}, B::SymTridiagonal{T}) at linalg/special.jl:139\n",
"+(A::SymTridiagonal{T}, B::Bidiagonal{T}) at linalg/special.jl:140\n",
"+(A::Diagonal{T}, B::UpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:151\n",
"+(A::UpperTriangular{T,S<:AbstractArray{T,2}}, B::Diagonal{T}) at linalg/special.jl:152\n",
"+(A::Diagonal{T}, B::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:151\n",
"+(A::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}, B::Diagonal{T}) at linalg/special.jl:152\n",
"+(A::Diagonal{T}, B::LowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:151\n",
"+(A::LowerTriangular{T,S<:AbstractArray{T,2}}, B::Diagonal{T}) at linalg/special.jl:152\n",
"+(A::Diagonal{T}, B::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:151\n",
"+(A::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}, B::Diagonal{T}) at linalg/special.jl:152\n",
"+(A::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}, B::SymTridiagonal{T}) at linalg/special.jl:158\n",
"+(A::SymTridiagonal{T}, B::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:159\n",
"+(A::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}, B::Tridiagonal{T}) at linalg/special.jl:158\n",
"+(A::Tridiagonal{T}, B::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:159\n",
"+(A::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}, B::Bidiagonal{T}) at linalg/special.jl:158\n",
"+(A::Bidiagonal{T}, B::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}) at linalg/special.jl:159\n",
"+(A::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}, B::Array{T,2}) at linalg/special.jl:158\n",
"+{Tv1,Ti1,Tv2,Ti2}(A_1::SparseMatrixCSC{Tv1,Ti1}, A_2::SparseMatrixCSC{Tv2,Ti2}) at sparse/sparsematrix.jl:1005\n",
"+(A::SparseMatrixCSC{Tv,Ti<:Integer}, B::Array{T,N}) at sparse/sparsematrix.jl:1017\n",
"+(A::SparseMatrixCSC{Tv,Ti<:Integer}, J::UniformScaling{T<:Number}) at sparse/sparsematrix.jl:3030\n",
"+{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}(Y::Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}, x::Union{Base.Dates.CompoundPeriod,Base.Dates.Period}) at dates/periods.jl:235\n",
"+{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},Q<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}(X::Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}, Y::Union{DenseArray{Q<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{Q<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}) at dates/periods.jl:236\n",
"+{T<:Base.Dates.TimeType,P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}(x::Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}, y::T<:Base.Dates.TimeType) at dates/arithmetic.jl:83\n",
"+{T<:Base.Dates.TimeType}(r::Range{T<:Base.Dates.TimeType}, x::Base.Dates.Period) at dates/ranges.jl:39\n",
"+{T<:Number}(x::AbstractArray{T<:Number,N}) at abstractarraymath.jl:49\n",
"+{S,T}(A::AbstractArray{S,N}, B::Range{T}) at arraymath.jl:78\n",
"+{S,T}(A::AbstractArray{S,N}, B::AbstractArray{T,N}) at arraymath.jl:96\n",
"+(A::AbstractArray{T,N}, x::Number) at arraymath.jl:139\n",
"+(x::Number, A::AbstractArray{T,N}) at arraymath.jl:140\n",
"+(x::Char, y::Integer) at char.jl:42\n",
"+{N}(index1::CartesianIndex{N}, index2::CartesianIndex{N}) at multidimensional.jl:42\n",
"+(J1::UniformScaling{T<:Number}, J2::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:27\n",
"+(J::UniformScaling{T<:Number}, B::BitArray{2}) at linalg/uniformscaling.jl:29\n",
"+(J::UniformScaling{T<:Number}, A::AbstractArray{T,2}) at linalg/uniformscaling.jl:30\n",
"+(J::UniformScaling{T<:Number}, x::Number) at linalg/uniformscaling.jl:31\n",
"+(x::Number, J::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:32\n",
"+{TA,TJ}(A::AbstractArray{TA,2}, J::UniformScaling{TJ}) at linalg/uniformscaling.jl:92\n",
"+{T}(a::Base.Pkg.Resolve.VersionWeights.HierarchicalValue{T}, b::Base.Pkg.Resolve.VersionWeights.HierarchicalValue{T}) at pkg/resolve/versionweight.jl:23\n",
"+(a::Base.Pkg.Resolve.VersionWeights.VWPreBuildItem, b::Base.Pkg.Resolve.VersionWeights.VWPreBuildItem) at pkg/resolve/versionweight.jl:85\n",
"+(a::Base.Pkg.Resolve.VersionWeights.VWPreBuild, b::Base.Pkg.Resolve.VersionWeights.VWPreBuild) at pkg/resolve/versionweight.jl:131\n",
"+(a::Base.Pkg.Resolve.VersionWeights.VersionWeight, b::Base.Pkg.Resolve.VersionWeights.VersionWeight) at pkg/resolve/versionweight.jl:185\n",
"+(a::Base.Pkg.Resolve.MaxSum.FieldValues.FieldValue, b::Base.Pkg.Resolve.MaxSum.FieldValues.FieldValue) at pkg/resolve/fieldvalue.jl:44\n",
"+{P<:Base.Dates.Period}(x::P<:Base.Dates.Period, y::P<:Base.Dates.Period) at dates/periods.jl:62\n",
"+(x::Base.Dates.Period, y::Base.Dates.Period) at dates/periods.jl:209\n",
"+(x::Base.Dates.CompoundPeriod, y::Base.Dates.Period) at dates/periods.jl:210\n",
"+(y::Base.Dates.Period, x::Base.Dates.CompoundPeriod) at dates/periods.jl:211\n",
"+(x::Base.Dates.CompoundPeriod, y::Base.Dates.CompoundPeriod) at dates/periods.jl:212\n",
"+(x::Base.Dates.CompoundPeriod, y::Base.Dates.TimeType) at dates/periods.jl:257\n",
"+(y::Base.Dates.Period, x::Base.Dates.TimeType) at dates/arithmetic.jl:66\n",
"+{T<:Base.Dates.TimeType}(x::Base.Dates.Period, r::Range{T<:Base.Dates.TimeType}) at dates/ranges.jl:40\n",
"+(x::Union{Base.Dates.CompoundPeriod,Base.Dates.Period}) at dates/periods.jl:220\n",
"+{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}(x::Union{Base.Dates.CompoundPeriod,Base.Dates.Period}, Y::Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}) at dates/periods.jl:234\n",
"+(dt::DateTime, y::Base.Dates.Year) at dates/arithmetic.jl:13\n",
"+(dt::Date, y::Base.Dates.Year) at dates/arithmetic.jl:17\n",
"+(dt::DateTime, z::Base.Dates.Month) at dates/arithmetic.jl:37\n",
"+(dt::Date, z::Base.Dates.Month) at dates/arithmetic.jl:43\n",
"+(x::Date, y::Base.Dates.Week) at dates/arithmetic.jl:60\n",
"+(x::Date, y::Base.Dates.Day) at dates/arithmetic.jl:62\n",
"+(x::DateTime, y::Base.Dates.Period) at dates/arithmetic.jl:64\n",
"+(x::Base.Dates.TimeType) at dates/arithmetic.jl:8\n",
"+(a::Base.Dates.TimeType, b::Base.Dates.Period, c::Base.Dates.Period) at dates/periods.jl:246\n",
"+(a::Base.Dates.TimeType, b::Base.Dates.Period, c::Base.Dates.Period, d::Base.Dates.Period...) at dates/periods.jl:248\n",
"+(x::Base.Dates.TimeType, y::Base.Dates.CompoundPeriod) at dates/periods.jl:252\n",
"+(x::Base.Dates.Instant) at dates/arithmetic.jl:4\n",
"+{T<:Base.Dates.TimeType}(x::AbstractArray{T<:Base.Dates.TimeType,N}, y::Union{Base.Dates.CompoundPeriod,Base.Dates.Period}) at dates/arithmetic.jl:76\n",
"+{T<:Base.Dates.TimeType}(y::Union{Base.Dates.CompoundPeriod,Base.Dates.Period}, x::AbstractArray{T<:Base.Dates.TimeType,N}) at dates/arithmetic.jl:77\n",
"+{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period}}(y::Base.Dates.TimeType, x::Union{DenseArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N},SubArray{P<:Union{Base.Dates.CompoundPeriod,Base.Dates.Period},N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD}}) at dates/arithmetic.jl:84\n",
"+(a, b, c, xs...) at operators.jl:103"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Base methods for the +() function\n",
"methods(+)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We have to create a method."
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import Base.+"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"+ (generic function with 172 methods)"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"+(u::Vector_2D, v::Vector_2D) = Vector_2D(u.x + v.x, u.y + v.y)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Vector_2D(2.0,2.0)"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"+(vector_a, vector_b)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Constraining field values</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can well imagine needing to constain the values that a type can hold. Below we create the Bloodpressure type with two fields that hold integer values. They cannot be negative and the systolic blood pressure must be higher than the diastolic blood pressure. We solve this problem by creating an inner constructor."
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"type BloodPressure\n",
" # Don't leave as Any\n",
" systolic::Int16\n",
" diastolic::Int16\n",
" function BloodPressure(s, d)\n",
" # Using short-circuit evaluations && and ||\n",
" s < 0 && throw(ArgumentError(\"Negative pressures are not allowed!\"))\n",
" s <= d && throw(ArgumentError(\"The systolic blood pressure must be higher than the diastolic blood pressure!\"))\n",
" isa(s, Integer) || throw(ArgumentError(\"Only integer values allowed!\"))\n",
" isa(d, Integer) || throw(ArgumentError(\"Only integer values allowed!\"))\n",
" new(s, d)\n",
" end\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"BloodPressure(120,80)"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bp_1 = BloodPressure(120, 80)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `bp_2 = BloodPressure(-1, 90)` will result in the error:\n",
"```\n",
"LoadError: ArgumentError: Negative pressures are not allowed!\n",
"while loading In[32], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `bp_2 = BloodPressure(80, 120)` will result in the error:\n",
"```\n",
"LoadError: ArgumentError: The systolic blood pressure must be higher than the diastolic blood pressure\n",
"while loading In[56], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `bp_2 = BloodPressure(120.0, 80)` will result in the error:\n",
"```\n",
"LoadError: ArgumentError: Only integer values allowed!\n",
"while loading In[95], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Beware. Using inner constructors with parametrized types can lead to problems."
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"type BloodPressureParametrized{T <: Real}\n",
" # Don't leave as Any\n",
" systolic::T\n",
" diastolic::T\n",
" function BloodPressureParametrized(s, d)\n",
" s < 0 && throw(ArgumentError(\"Negative pressures are not allowed!\"))\n",
" s <= d && throw(ArgumentError(\"The systolic blood pressure must be higher than the diastolic blood pressure!\"))\n",
" isa(s, Integer) || throw(ArgumentError(\"Only integer values allowed!\"))\n",
" isa(d, Integer) || throw(ArgumentError(\"Only integer values allowed!\"))\n",
" new(s, d)\n",
" end\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `bp_3 = BloodPressureParametrized(120, 80)` will result in the error;\n",
"```\n",
"LoadError: MethodError: `convert` has no method matching convert(::Type{BloodPressureParametrized{T<:Real}}, ::Int64, ::Int64)\n",
"This may have arisen from a call to the constructor BloodPressureParametrized{T<:Real}(...),\n",
"since type constructors fall back to convert methods.\n",
"Closest candidates are:\n",
" call{T}(::Type{T}, ::Any)\n",
" convert{T}(::Type{T}, !Matched::T)\n",
"while loading In[102], in expression starting on line 1\n",
"\n",
" in call at essentials.jl:57\n",
" ```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we have to specify the type during the instantiation."
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"BloodPressureParametrized{Int64}(120,80)"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bp_3 = BloodPressureParametrized{Int}(120, 80)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"type BloodPressureParametrizedFixed{T <: Real}\n",
" systolic::T\n",
" diastolic::T\n",
" function BloodPressureParametrizedFixed(s, d)\n",
" s < 0 && throw(ArgumentError(\"Negative pressures are not allowed!\"))\n",
" s <= d && throw(ArgumentError(\"The systolic blood pressure must be higher than the diastolic blood pressure!\"))\n",
" new(s, d)\n",
" end\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can fix this by the assignment below."
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"BloodPressureParametrizedFixed{T<:Real}"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# A bit of an effort\n",
"BloodPressureParametrizedFixed{T}(systolic::T, diastolic::T) = BloodPressureParametrizedFixed{T}(systolic, diastolic)"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"BloodPressureParametrizedFixed{Int64}(120,80)"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bp_4 = BloodPressureParametrizedFixed(120, 80)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can get way more specific. In the code below we tell Julia that if we pass integers to the type, they should be expressed as floating point values."
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"BloodPressureParametrizedFixed{T<:Real}"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"BloodPressureParametrizedFixed{T <: Int}(systolic::T, diastolic::T) = BloodPressureParametrizedFixed{Float64}(systolic, diastolic)"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"BloodPressureParametrizedFixed{Float64}(120.0,80.0)"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bp_5 = BloodPressureParametrizedFixed(120, 80)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>More complex parameters</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Up until now we have constrained ourselves to a single parameter. It is possible, though, to create more than one. Below we create a type called `Relook`. It has one fieldname called `duration`, which must be of subtype, `Real`. There is also a second parameter."
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"type Relook{N, T<:Real}\n",
" duration::T\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `patient_1 = Relook(3, 60)` will result in the error:\n",
"```\n",
"LoadError: MethodError: `convert` has no method matching convert(::Type{Relook{N,T}}, ::Int64, ::Int64)\n",
"This may have arisen from a call to the constructor Relook{N,T}(...),\n",
"since type constructors fall back to convert methods.\n",
"Closest candidates are:\n",
" call{T}(::Type{T}, ::Any)\n",
" convert{T}(::Type{T}, !Matched::T)\n",
"while loading In[175], in expression starting on line 1\n",
"\n",
" in call at essentials.jl:57\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Relook{4,Int16}(60)"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We have to specify the type of the second parameter\n",
"patient_1 = Relook{4, Int16}(60)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"60"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"patient_1.duration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now want to add only objects (instances) with the same value in the first parameter."
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"+ (generic function with 173 methods)"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"+{N, T}(u::Relook{N, T}, v::Relook{N, T}) = Relook{N, T}(u.duration + v.duration)"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Relook{4,Int16}(70)"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"patient_2 = Relook{4, Int16}(70)"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Relook{4,Int16}(130)"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"patient_1 + patient_2"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Relook{3,Int16}(70)"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"patient_3 = Relook{3, Int16}(70)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `patient_1 + patient_3` will now result in the error:\n",
"```LoadError: MethodError: `+` has no method matching +(::Relook{4,Int16}, ::Relook{3,Int16})\n",
"Closest candidates are:\n",
" +(::Any, ::Any, !Matched::Any, !Matched::Any...)\n",
" +{N,T}(::Relook{N,T}, !Matched::Relook{N,T})\n",
"while loading In[191], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Relook{4.0,Int16}(70)"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"patient_4 = Relook{4.0, Int16}(70)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `patient_1 + patient_4` will also result in an error, because the types of `N` do not match. The error would be:\n",
"```\n",
"LoadError: MethodError: `+` has no method matching +(::Relook{4,Int16}, ::Relook{4.0,Int16})\n",
"Closest candidates are:\n",
" +(::Any, ::Any, !Matched::Any, !Matched::Any...)\n",
" +{N,T}(::Relook{N,T}, !Matched::Relook{N,T})\n",
" +{N,T1,T2}(::Relook{N,T1}, !Matched::Relook{N,T2})\n",
"while loading In[210], in expression starting on line 1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below we fix the fieldname type mismatch."
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"+ (generic function with 174 methods)"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"+{N, T1, T2}(u::Relook{N, T1}, v::Relook{N, T2}) = Relook{N, promote_type(T1, T2)}(u.duration + v.duration)"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Relook{4,Float64}(60.0)"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"patient_5 = Relook{4, Float64}(60)"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Relook{4,Float64}(120.0)"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# N = 4 for both patient_1 and patient_5\n",
"# T for patient_1 is Int16 and T for patient_2 is Float64\n",
"patient_1 + patient_5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we want to throw an error if the number of relooks are not equal when trying to add to obejcts of the `Relook` type, we can do the following."
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"+ (generic function with 175 methods)"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"+{N1, N2, T}(u::Relook{N1, T}, v::Relook{N2, T}) = \n",
"throw(ArgumentError(\"Cannot add durations when the number of relooks do not match.\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `patient_1 + patient_3` will now result in the error:\n",
"```\n",
"LoadError: ArgumentError: Cannot add durations when the number of relooks do not match.\n",
"while loading In[237], in expression starting on line 1\n",
"\n",
" in + at In[236]:1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What about calculating the natural logarithm of the duration of a `Relook` object? We could just specify the field name."
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"4.0943445622221"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"log(patient_1.duration)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Better still, we could specify wat the `log` function actually does with a `Relook` object."
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import Base.log"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"log (generic function with 20 methods)"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"log(u::Relook) = log(u.duration)"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"4.0943445622221"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"log(patient_1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can specify a `convert` method that will convert all our `Relook` objects to numerical values which we can pass to Julia functions."
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import Base.convert"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"convert (generic function with 538 methods)"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The float() function tries to convert a value to a floating point value\n",
"convert(::Type{AbstractFloat}, u::Relook) = float(u.duration)"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"1.7781512503836436"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Covreting our Relook object and passing it to log10()\n",
"log10(convert(AbstractFloat, patient_1))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Screen output of a user-defined type</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can create some meaning to our types by the way an object of the type is represented on the screen. Above we just saw two values we instantiation our type `Relook`. Let's change that a bit by overloading the `show` function."
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import Base.show"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"show (generic function with 107 methods)"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"show{N, T}(io::IO, u::Relook{N, T}) = print(io, \"Patient with \", N, \" relook procedures totalling \", u.duration,\n",
"\" minutes.\")"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Patient with 4 relook procedures totalling 60 minutes."
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"patient_6 = Relook{4, Int16}(60)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 0.4.6",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
================================================
FILE: .ipynb_checkpoints/Week4_4Data-checkpoint.ipynb
================================================
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,900,100italic,300italic,400italic,500italic,700italic,800italic,900italic' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=Arvo:400,700,400italic' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=PT+Mono' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>\n",
"<link href='http://fonts.googleapis.com/css?family=Philosopher:400,700,400italic,700italic' rel='stylesheet' type='text/css'>\n",
"\n",
"<style>\n",
"\n",
"@font-face {\n",
" font-family: \"Computer Modern\";\n",
" src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n",
"}\n",
"\n",
"#notebook_panel { /* main background */\n",
" background: #ddd;\n",
" color: #000000;\n",
"}\n",
"\n",
"\n",
"\n",
"/* Formatting for header cells */\n",
".text_cell_render h1 {\n",
" font-family: 'Philosopher', sans-serif;\n",
" font-weight: 400;\n",
" font-size: 2.2em;\n",
" line-height: 100%;\n",
" color: rgb(0, 80, 120);\n",
" margin-bottom: 0.1em;\n",
" margin-top: 0.1em;\n",
" display: block;\n",
"}\t\n",
".text_cell_render h2 {\n",
" font-family: 'Philosopher', serif;\n",
" font-weight: 400;\n",
" font-size: 1.9em;\n",
" line-height: 100%;\n",
" color: rgb(200,100,0);\n",
" margin-bottom: 0.1em;\n",
" margin-top: 0.1em;\n",
" display: block;\n",
"}\t\n",
"\n",
".text_cell_render h3 {\n",
" font-family: 'Philosopher', serif;\n",
" margin-top:12px;\n",
" margin-bottom: 3px;\n",
" font-style: italic;\n",
" color: rgb(94,127,192);\n",
"}\n",
"\n",
".text_cell_render h4 {\n",
" font-family: 'Philosopher', serif;\n",
"}\n",
"\n",
".text_cell_render h5 {\n",
" font-family: 'Alegreya Sans', sans-serif;\n",
" font-weight: 300;\n",
" font-size: 16pt;\n",
" color: grey;\n",
" font-style: italic;\n",
" margin-bottom: .1em;\n",
" margin-top: 0.1em;\n",
" display: block;\n",
"}\n",
"\n",
".text_cell_render h6 {\n",
" font-family: 'PT Mono', sans-serif;\n",
" font-weight: 300;\n",
" font-size: 10pt;\n",
" color: grey;\n",
" margin-bottom: 1px;\n",
" margin-top: 1px;\n",
"}\n",
"\n",
".CodeMirror{\n",
" font-family: \"PT Mono\";\n",
" font-size: 100%;\n",
"}\n",
"\n",
"</style>\n",
"\n"
],
"text/plain": [
"HTML{ASCIIString}(\"<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,900,100italic,300italic,400italic,500italic,700italic,800italic,900italic' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=Arvo:400,700,400italic' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=PT+Mono' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>\\n<link href='http://fonts.googleapis.com/css?family=Philosopher:400,700,400italic,700italic' rel='stylesheet' type='text/css'>\\n\\n<style>\\n\\n@font-face {\\n font-family: \\\"Computer Modern\\\";\\n src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\\n}\\n\\n#notebook_panel { /* main background */\\n background: #ddd;\\n color: #000000;\\n}\\n\\n\\n\\n/* Formatting for header cells */\\n.text_cell_render h1 {\\n font-family: 'Philosopher', sans-serif;\\n font-weight: 400;\\n font-size: 2.2em;\\n line-height: 100%;\\n color: rgb(0, 80, 120);\\n margin-bottom: 0.1em;\\n margin-top: 0.1em;\\n display: block;\\n}\\t\\n.text_cell_render h2 {\\n font-family: 'Philosopher', serif;\\n font-weight: 400;\\n font-size: 1.9em;\\n line-height: 100%;\\n color: rgb(200,100,0);\\n margin-bottom: 0.1em;\\n margin-top: 0.1em;\\n display: block;\\n}\\t\\n\\n.text_cell_render h3 {\\n font-family: 'Philosopher', serif;\\n margin-top:12px;\\n margin-bottom: 3px;\\n font-style: italic;\\n color: rgb(94,127,192);\\n}\\n\\n.text_cell_render h4 {\\n font-family: 'Philosopher', serif;\\n}\\n\\n.text_cell_render h5 {\\n font-family: 'Alegreya Sans', sans-serif;\\n font-weight: 300;\\n font-size: 16pt;\\n color: grey;\\n font-style: italic;\\n margin-bottom: .1em;\\n margin-top: 0.1em;\\n display: block;\\n}\\n\\n.text_cell_render h6 {\\n font-family: 'PT Mono', sans-serif;\\n font-weight: 300;\\n font-size: 10pt;\\n color: grey;\\n margin-bottom: 1px;\\n margin-top: 1px;\\n}\\n\\n.CodeMirror{\\n font-family: \\\"PT Mono\\\";\\n font-size: 100%;\\n}\\n\\n</style>\\n\\n\")"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Setting up a custom stylesheet in IJulia\n",
"file = open(\"style.css\") # A .css file in the same folder as this notebook file\n",
"styl = readall(file) # Read the file\n",
"HTML(\"$styl\") # Output as HTML"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>In this lesson</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- [Introduction](#Introduction)\n",
"- [Importing the packages for this lesson](#Importing-the-packages-for-this-lesson)\n",
"- [Outcome](#Outcome)\n",
"- [The standard normal distribution](#The-standard-normal-distribution)\n",
"- [Using the Distributions package](#Using-the-Distributions-package)\n",
"- [Comparing samples](#Comparing-samples)\n",
"- [Plotly](#Plotly)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Introduction</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Data is everywhere and working with data is very important in scientific computing. Data point values come in patterns, called distributions. Whether you are modelling, getting data from a research project, or simply want ot manufactor some data, Julia is the place to go."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We know about the `rand()` and `randn()` functions, but by using the `Distributions` package we can do much, much more."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Back to the top](#In-this-lesson)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Importing the packages for this lesson</h2>"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"using Distributions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You should have the `PlotlyJS` package installed."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Plots.PlotlyJSBackend()"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Plots\n",
"plotlyjs()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: New definition \n",
" +(AbstractArray, DataArrays.DataArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:276\n",
"is ambiguous with: \n",
" +(WoodburyMatrices.SymWoodbury, AbstractArray{T<:Any, 2}) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:107.\n",
"To fix, define \n",
" +(WoodburyMatrices.SymWoodbury, DataArrays.DataArray{T<:Any, 2})\n",
"before the new definition.\n",
"WARNING: New definition \n",
" +(AbstractArray, DataArrays.AbstractDataArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:300\n",
"is ambiguous with: \n",
" +(WoodburyMatrices.SymWoodbury, AbstractArray{T<:Any, 2}) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:107.\n",
"To fix, define \n",
" +(WoodburyMatrices.SymWoodbury, DataArrays.AbstractDataArray{T<:Any, 2})\n",
"before the new definition.\n"
]
}
],
"source": [
"using StatPlots"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: Method definition combinations(Any, Integer) in module Base at combinatorics.jl:182 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/combinations.jl:42.\n",
"WARNING: Method definition permutations(Any) in module Base at combinatorics.jl:219 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:24.\n",
"WARNING: Method definition partitions(Integer) in module Base at combinatorics.jl:252 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:26.\n",
"WARNING: Method definition partitions(Integer, Integer) in module Base at combinatorics.jl:318 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:93.\n",
"WARNING: Method definition partitions(AbstractArray{T<:Any, 1}) in module Base at combinatorics.jl:380 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:158.\n",
"WARNING: Method definition partitions(AbstractArray{T<:Any, 1}, Int64) in module Base at combinatorics.jl:447 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:228.\n",
"WARNING: Method definition factorial(#T<:Integer, #T<:Integer) in module Base at combinatorics.jl:56 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:18.\n",
"WARNING: Method definition factorial(Integer, Integer) in module Base at combinatorics.jl:66 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:28.\n",
"WARNING: Method definition parity(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:642 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:221.\n",
"WARNING: Method definition nthperm(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:92 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:161.\n",
"WARNING: Method definition nthperm(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:89 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:157.\n",
"WARNING: Method definition nthperm!(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:70 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:136.\n",
"WARNING: Method definition prevprod(Array{Int64, 1}, Any) in module Base at combinatorics.jl:565 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:354.\n",
"WARNING: Method definition levicivita(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:611 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:188.\n"
]
}
],
"source": [
"using HypothesisTests"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"using DataFrames"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Precompiling module GLM...\n"
]
}
],
"source": [
"using GLM"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>Outcome</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"After successfully completing this lecture, you will be able to:\n",
"\n",
"- Understand and plot the standard normal distribution\n",
"- Create a variety of random value from different distributions using the `Distributions` package\n",
"- Plot some of the distributions in the `Distributions` package\n",
"- Create your own data using a distribution and its parameters\n",
"- Use the online plotting library `Plotly`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>The standard normal distribution</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Julie function `rand()` allows us to return an array of randomly selected values. The values come from a specific distribution, namely the **standard normal** distribution. The majority of values cluster around the mean of $ 0 $ and a standard deviation of $ 1 $. Let's get $ 1000 $ such values and attach this array to the variable `norm1`."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# We will put a semicolon at the end to supress the output\n",
"norm1 = randn(1000);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can plot this as histogram. In the example below, we will use the keyword argument `bins`. Setting it to $ 10 $ means that between the minimum and maximum value we create $ 10 $ equally sized ranges and count how many values occur in each range."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<script charset=\"utf-8\" type='text/javascript'>\n",
" // This script w
gitextract_pjvm24r9/ ├── .gitattributes ├── .gitignore ├── .ipynb_checkpoints/ │ ├── Collections_using_v_1-checkpoint.ipynb │ ├── Week 3_Peer graded quiz on Types-checkpoint.ipynb │ ├── Week 4_Peer graded quiz on Gadfly-checkpoint.ipynb │ ├── Week 4_Peer graded quiz on data-checkpoint.ipynb │ ├── Week3_Honors1-Types-checkpoint.ipynb │ └── Week4_4Data-checkpoint.ipynb ├── CCS.csv ├── Collections.ipynb ├── Collections_using_v_1.ipynb ├── Countries.csv ├── Functions.ipynb ├── Functions_using_v_1.ipynb ├── GadflyTutorialData.csv ├── Indicators.csv ├── README.md ├── Week 3_Peer graded quiz on Types.ipynb ├── Week 4_Peer graded quiz on Gadfly.ipynb ├── Week 4_Peer graded quiz on data.ipynb ├── Week1_1-WhySpecial.ipynb ├── Week1_2-JuliaBox.ipynb ├── Week1_3-REPL.ipynb ├── Week1_4-ArithmeticalExp.ipynb ├── Week1_5-LogicalExp.ipynb ├── Week1_6-TypeSystem.ipynb ├── Week1_7-Variables.ipynb ├── Week1_8-Functions1.ipynb ├── Week1_9-Functions2.ipynb ├── Week2_1-EbolaExample.ipynb ├── Week2_2_1-LoadingData.ipynb ├── Week2_2_2_CreateCSV.ipynb ├── Week2_3-ForLoops.ipynb ├── Week2_4-SimplePlots.ipynb ├── Week2_5-MultipleCurves.ipynb ├── Week3_1-SIRmodels.ipynb ├── Week3_2-MoreSIR.ipynb ├── Week3_3-PlottingData.ipynb ├── Week3_4-RoughFit.ipynb ├── Week3_Honors1-Types.ipynb ├── Working with data_using_v_1.ipynb ├── style.css ├── wikipediaEVDdatesconverted.csv └── wikipediaEVDraw.csv
Copy disabled (too large)
Download .json
Condensed preview — 44 files, each showing path, character count, and a content snippet. Download the .json file for the full structured content (10,576K chars).
[
{
"path": ".gitattributes",
"chars": 378,
"preview": "# Auto detect text files and perform LF normalization\n* text=auto\n\n# Custom for Visual Studio\n*.cs diff=csharp\n\n# St"
},
{
"path": ".gitignore",
"chars": 649,
"preview": "# Windows image file caches\nThumbs.db\nehthumbs.db\n\n# Folder config file\nDesktop.ini\n\n# Recycle Bin used on file shares\n$"
},
{
"path": ".ipynb_checkpoints/Collections_using_v_1-checkpoint.ipynb",
"chars": 41526,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Collections\"\n ]\n },\n {\n \"ce"
},
{
"path": ".ipynb_checkpoints/Week 3_Peer graded quiz on Types-checkpoint.ipynb",
"chars": 5369,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Peer-graded quiz for `Types`\"\n "
},
{
"path": ".ipynb_checkpoints/Week 4_Peer graded quiz on Gadfly-checkpoint.ipynb",
"chars": 6035,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Peer-graded quiz on Gadfly\"\n ]\n"
},
{
"path": ".ipynb_checkpoints/Week 4_Peer graded quiz on data-checkpoint.ipynb",
"chars": 11218,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Peer-graded quiz for data\"\n ]\n "
},
{
"path": ".ipynb_checkpoints/Week3_Honors1-Types-checkpoint.ipynb",
"chars": 118361,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": ".ipynb_checkpoints/Week4_4Data-checkpoint.ipynb",
"chars": 1308239,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "CCS.csv",
"chars": 7980,
"preview": "\"PatientID\",\"Cat1\",\"Cat2\",\"Var1\",\"Var2\",\"Var3\"\n1,\"A\",\"C\",38.25682170735211,5.939131803063266,35.05790787394423\n2,\"A\",\"C\""
},
{
"path": "Collections.ipynb",
"chars": 38997,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 86,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\""
},
{
"path": "Collections_using_v_1.ipynb",
"chars": 41526,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Collections\"\n ]\n },\n {\n \"ce"
},
{
"path": "Countries.csv",
"chars": 30526,
"preview": "\"iso3c\",\"iso2c\",\"name\",\"region\",\"capital\",\"longitude\",\"latitude\",\"income\",\"lending\"\n\"ABW\",\"AW\",\"Aruba\",\"Latin America & "
},
{
"path": "Functions.ipynb",
"chars": 12886,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\":"
},
{
"path": "Functions_using_v_1.ipynb",
"chars": 46802,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Functions\"\n ]\n },\n {\n \"cell"
},
{
"path": "GadflyTutorialData.csv",
"chars": 6095,
"preview": "Patient,Gender,Age,Variable1,Variable2,Variable3,Variable4,Category1,Category2,Category3\r1,F,37,22.3,104,5.3,64,A,C,P\r2,"
},
{
"path": "Indicators.csv",
"chars": 7545943,
"preview": "\"indicator\",\"name\",\"description\",\"source_database\",\"source_organization\"\n\"1.0.HCount.1.90usd\",\"Poverty Headcount ($1.90 "
},
{
"path": "README.md",
"chars": 1389,
"preview": "# JuliaCourseNotebooks\n\nJupyter notebooks and Juno .jl files for the Julia Scientific Programming course on Coursera\n\nTh"
},
{
"path": "Week 3_Peer graded quiz on Types.ipynb",
"chars": 5369,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Peer-graded quiz for `Types`\"\n "
},
{
"path": "Week 4_Peer graded quiz on Gadfly.ipynb",
"chars": 6035,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Peer-graded quiz on Gadfly\"\n ]\n"
},
{
"path": "Week 4_Peer graded quiz on data.ipynb",
"chars": 11218,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"# Peer-graded quiz for data\"\n ]\n "
},
{
"path": "Week1_1-WhySpecial.ipynb",
"chars": 11626,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": true\n },\n \"outp"
},
{
"path": "Week1_2-JuliaBox.ipynb",
"chars": 14436,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 4,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week1_3-REPL.ipynb",
"chars": 15937,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 2,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week1_4-ArithmeticalExp.ipynb",
"chars": 12334,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 4,\n \"metadata\": {\n \"collapsed\": true\n },\n \"outp"
},
{
"path": "Week1_5-LogicalExp.ipynb",
"chars": 19377,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 17,\n \"metadata\": {\n \"collapsed\": false\n },\n \"ou"
},
{
"path": "Week1_6-TypeSystem.ipynb",
"chars": 23854,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": true\n },\n \"outp"
},
{
"path": "Week1_7-Variables.ipynb",
"chars": 23993,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 11,\n \"metadata\": {\n \"collapsed\": false\n },\n \"ou"
},
{
"path": "Week1_8-Functions1.ipynb",
"chars": 22699,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 11,\n \"metadata\": {\n \"collapsed\": false\n },\n \"ou"
},
{
"path": "Week1_9-Functions2.ipynb",
"chars": 18549,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 11,\n \"metadata\": {\n \"collapsed\": true\n },\n \"out"
},
{
"path": "Week2_1-EbolaExample.ipynb",
"chars": 14030,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week2_2_1-LoadingData.ipynb",
"chars": 12521,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": true\n },\n \"outp"
},
{
"path": "Week2_2_2_CreateCSV.ipynb",
"chars": 9215,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week2_3-ForLoops.ipynb",
"chars": 22244,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week2_4-SimplePlots.ipynb",
"chars": 92271,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week2_5-MultipleCurves.ipynb",
"chars": 189606,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week3_1-SIRmodels.ipynb",
"chars": 96728,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week3_2-MoreSIR.ipynb",
"chars": 49400,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week3_3-PlottingData.ipynb",
"chars": 49032,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Week3_4-RoughFit.ipynb",
"chars": 66275,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": true\n },\n \"outp"
},
{
"path": "Week3_Honors1-Types.ipynb",
"chars": 118361,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {\n \"collapsed\": false\n },\n \"out"
},
{
"path": "Working with data_using_v_1.ipynb",
"chars": 68299,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"## Working with data\"\n ]\n },\n {"
},
{
"path": "style.css",
"chars": 2062,
"preview": "<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,900,100italic,300italic,400ital"
},
{
"path": "wikipediaEVDdatesconverted.csv",
"chars": 2323,
"preview": "613,28637,11314,3804,2536,10675,4808,14122,3955\n606,28634,11314,3804,2536,10672,4808,14122,3955\n599,28635,11314,3805,253"
},
{
"path": "wikipediaEVDraw.csv",
"chars": 2752,
"preview": "25 Nov 2015,28637,11314,3804,2536,10675,4808,14122,3955\n18 Nov 2015,28634,11314,3804,2536,10672,4808,14122,3955\n11 Nov 2"
}
]
About this extraction
This page contains the full source code of the juanklopper/JuliaCourseNotebooks GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 44 files (9.7 MB), approximately 2.6M tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.