Skip to content

Instantly share code, notes, and snippets.

#Create matrix
A = rand(3,9)
#Sum over rows -> matrix
typeof(sum(A, 1)) == Matrix{Float64} #true
#Sum over cols -> matrix
typeof(sum(A,2)) == Matrix{Float64} #true
#This is expected, but what is the best way to extract the vector? This?
@pkofod
pkofod / devec.jl
Last active October 7, 2015 20:20
using Devectorize
function test0()
vector = rand(8000)
phat = zeros(8000)
@time for i = 1:1000
for j = 1:8000
phat[j] = 1./(1+exp(-vector [j]))
end
end
type ML
vector
phat
end
ml = ML(rand(8000), zeros(8000))
function test6(a)
@time for i = 1:1000
for j = 1:8000
type Type1
a::Matrix{Float64} # why not vector of vectors?
b::Vector{Matrix{Float64}}
c::Vector{Float64}
d::Float64
e::Int64
end
type Type2{T}
a::Matrix{T} # why not vector of vectors?
type Type1
a::Matrix{Float64} # why not vector of vectors?
b::Vector{Matrix{Float64}}
c::Vector{Float64}
d::Float64
e::Int64
end
type Type2{T}
a::Matrix{T} # why not vector of vectors?
julia> @code_warntype [sprand(10,10,.1) rand(10,10)]
Variables:
#self#::Base.#hcat
Xin::Tuple{SparseMatrixCSC{Float64,Int64},Array{Float64,2}}
X::Array{SparseMatrixCSC{Tv,Ti<:Integer},1}
#temp#@_4::Int64
#temp#@_5::Int64
#temp#@_6::Int64
x::Union{Array{Float64,2},SparseMatrixCSC{Float64,Int64}}
#temp#@_8::Int64
using Benchmarks
mydot{T<:BLAS.BlasReal, TI<:Integer}(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) = BLAS.dot(sub(x, rx), sub(y, ry))
mydot{T<:BLAS.BlasComplex, TI<:Integer}(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) = BLAS.dotc(sub(x, rx), sub(y, ry))
n = 1000
m = 20
step_size = 5
x = rand(n)
y = rand(n)
xc = rand(Complex128, n)
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\usepgfplotslibrary{fillbetween}
\begin{tikzpicture}
\begin{axis}
\addplot[name path=function, domain=-1.5:1] {x^2};
\path[name path=axis] (axis cs:-1.5,0.0) -- (axis cs:1,0.0);
\addplot[yellow] fill between[of = function and axis];
julia> using Base.Test
julia> # Quadratic objective function
# For (A*x-b)^2/2
function quadratic!(x, g, AtA, Atb, tmp)
calc_grad = !(g === nothing)
A_mul_B!(tmp, AtA, x)
v = dot(x,tmp)/2 + dot(Atb,x)
if calc_grad
julia> using Base.Test
julia> # Quadratic objective function
# For (A*x-b)^2/2
function quadratic!(x, g, AtA, Atb, tmp)
calc_grad = !(g === nothing)
A_mul_B!(tmp, AtA, x)
v = dot(x,tmp)/2 + dot(Atb,x)
if calc_grad
for i = 1:length(g)