Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Commit

Permalink
Remove mention of "implementations of core julia functions"
Browse files Browse the repository at this point in the history
Not needed since JuliaLang/julia#10314
  • Loading branch information
timholy committed Apr 3, 2015
1 parent 7864e19 commit 00d2874
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
4 changes: 0 additions & 4 deletions doc/README_0.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ with:
x: [0.0,15.0,0.0634665,0.0951998,0.126933,0.158666,0.1904,0.222133,0.253866,0.285599 … 2.85599,2.88773,2.91946,2.95119,2.98293,3.01466,3.04639,3.07813,3.10986,3.14159]
```

## Extensions of core Julia functions

This package contains versions of `map` and `map!` that are enabled for types.

## Inner workings

This package uses shameless hacks to implement closures that behave much like
Expand Down
63 changes: 0 additions & 63 deletions src/FastAnonymous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,67 +181,4 @@ function modscope(mod, ex::Expr)
modscope(modscope(mod, ex.args[1]), ex.args[2])
end


#### Methods using @anon-created "functions"

function map(f::AbstractClosure, A::AbstractArray)
if isempty(A); return similar(A); end
first = f(A[1])
dest = similar(A, typeof(first))
dest[1] = first
return map_to!(f, 2, dest, A)
end

# To resolve some ambiguities
map!(f::AbstractClosure, dest::AbstractVector, r::Range) = _map!(f, dest, r)
map!(f::AbstractClosure, dest::AbstractArray, r::Range) = _map!(f, dest, r)
function _map!{ast_p,argnames,V}(f::AbstractClosure{ast_p,argnames,V}, dest::AbstractArray, r::Range)
length(dest) == length(r) || throw(DimensionMismatch("length of dest and r must match"))
i = 1
for ri in r
@inbounds dest[i] = f(ri)
i += 1
end
dest
end

function map!{T,S,N,ast_p,argnames,V}(f::AbstractClosure{ast_p,argnames,V}, dest::AbstractArray{S,N}, A::AbstractArray{T,N})
for d = 1:N
size(dest,d) == size(A,d) || throw(DimensionMismatch("size of dest and A must match"))
end
for I in eachindex(A)
@inbounds dest[I] = f(A[I])
end
dest
end

function map!{T,N,ast_p,argnames,V}(f::AbstractClosure{ast_p,argnames,V}, dest::AbstractArray, A::AbstractArray{T,N})
length(dest) == length(A) || throw(DimensionMismatch("length of dest and A must match"))
k = 0
for a in A
@inbounds dest[k+1] = f(a)
end
dest
end

function map_to!{T,ast_p,argnames,V}(f::AbstractClosure{ast_p,argnames,V}, offs, dest::AbstractArray{T}, A::AbstractArray)
# map to dest array, checking the type of each result. if a result does not
# match, widen the result type and re-dispatch.
@inbounds for i = offs:length(A)
el = f(A[i])
S = typeof(el)
if S === T || S <: T
dest[i] = el::T
else
R = typejoin(T, S)
new = similar(dest, R)
copy!(new,1, dest,1, i-1)
new[i] = el
return map_to!(f, i+1, new, A)
end
end
return dest
end


end # module

0 comments on commit 00d2874

Please sign in to comment.