Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Apr 14, 2012
2 parents 8396c0a + d04fdf4 commit 7d45ea5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
2 changes: 1 addition & 1 deletion base/ascii.jl
Expand Up @@ -14,7 +14,7 @@ ref(s::ASCIIString, i::Int) = char(s.data[i])

ref(s::ASCIIString, r::Vector) = ASCIIString(ref(s.data,r))
ref(s::ASCIIString, r::Range1{Int}) = ASCIIString(ref(s.data,r))
ref(s::ASCIIString, indx::Array{Int,1}) = ASCIIString(s.data[indx])
ref(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString(s.data[indx])
strchr(s::ASCIIString, c::Char) = c < 0x80 ? memchr(s.data, c) : 0
strcat(a::ASCIIString, b::ASCIIString, c::ASCIIString...) = ASCIIString(memcat(a,b,c...))

Expand Down
10 changes: 5 additions & 5 deletions base/intfuncs.jl
Expand Up @@ -3,11 +3,11 @@
isodd(n::Integer) = bool(rem(n,2))
iseven(n::Integer) = !isodd(n)

sign{T<:Integer}(x::T) = convert(T,(x > 0)-(x < 0))
sign{T<:Unsigned}(x::T) = convert(T,(x > 0))
sign{T<:Integer}(x::T) = convert(T,(x>0)-(x<0))
sign{T<:Unsigned}(x::T) = convert(T,(x>0))

signbit(x::Unsigned) = 0
signbit(x::Int8 ) = int(x>>>7 )
signbit(x::Int8 ) = int(x>>>7)
signbit(x::Int16) = int(x>>>15)
signbit(x::Int32) = int(x>>>31)
signbit(x::Int64) = int(x>>>63)
Expand All @@ -17,14 +17,14 @@ flipsign(x::Int64, y::Int64) = boxsi64(flipsign_int64(unbox64(x),unbox64(y)))

flipsign{T<:Signed}(x::T,y::T) = flipsign(int(x),int(y))
flipsign(x::Signed, y::Signed) = flipsign(promote(x,y)...)
flipsign(x::Signed, y::Real) = flipsign(x, -oftype(x,signbit(y)))
flipsign(x::Signed, y::Float32) = flipsign(x, reinterpret(Int32,y))
flipsign(x::Signed, y::Float64) = flipsign(x, reinterpret(Int64,y))
flipsign(x::Signed, y::Real) = flipsign(x, -oftype(x,signbit(y)))

copysign(x::Signed, y::Signed) = flipsign(x, x$y)
copysign(x::Signed, y::Real) = copysign(x, -oftype(x,signbit(y)))
copysign(x::Signed, y::Float32) = copysign(x, reinterpret(Int32,y))
copysign(x::Signed, y::Float64) = copysign(x, reinterpret(Int64,y))
copysign(x::Signed, y::Real) = copysign(x, -oftype(x,signbit(y)))

abs(x::Unsigned) = x
abs(x::Signed) = flipsign(x,x)
Expand Down
17 changes: 7 additions & 10 deletions base/linalg.jl
Expand Up @@ -389,22 +389,19 @@ diagmm(A::Matrix, b::Vector) =
diagmm(b::Vector, A::Matrix) =
diagmm!(Array(promote_type(eltype(A),eltype(b)),size(A)), b, A)

^(A::AbstractMatrix, p::Integer) = p < 0 ? inv(A^-p) : power_by_squaring(A,p)
^(A::AbstractMatrix, p::Integer) =
size(A,1) != size(A,2) ? error("matrix must be square") :
p < 0 ? A^float(p) : power_by_squaring(A,p)

function ^(A::AbstractMatrix, p::Number)
if integer_valued(p)
ip = integer(real(p))
if ip < 0
return inv(power_by_squaring(A, -ip))
else
return power_by_squaring(A, ip)
end
if p >= 0 && integer_valued(p)
return power_by_squaring(A, integer(real(p)))
end
if size(A,1) != size(A,2)
error("matrix must be square")
end
(v, X) = eig(A)
if isreal(v) && any(v<0)
v, X = eig(A)
if isreal(v) && any(v < 0)
v = complex(v)
end
if ishermitian(A)
Expand Down
12 changes: 1 addition & 11 deletions base/regex.jl
Expand Up @@ -129,17 +129,7 @@ function split(s::String, regex::Regex, include_empty::Bool, limit::Integer)
end
return strs
end

split(s::String, x::String, incl::Bool, limit::Integer) =
strwidth(x) == 1 ? split(s, x[1], incl, limit) :
split(s, Regex(strcat("\\Q",x)), incl, limit)

split(s::String, regex::Regex, include_empty::Bool) =
split(s, regex, include_empty, 0)

split(s::String, x::String, incl::Bool) =
strwidth(x) == 1 ? split(s, x[1], incl) :
split(s, Regex(strcat("\\Q",x)), incl)
split(s::String, regex::Regex, include_empty::Bool) = split(s, regex, include_empty, 0)

replace(s::String, regex::Regex, repl::String, limit::Integer) =
join(split(s, regex, true, limit), repl)
Expand Down
56 changes: 48 additions & 8 deletions base/string.jl
Expand Up @@ -14,7 +14,7 @@ ref(s::String, i::Int) = next(s,i)[1]
ref(s::String, i::Integer) = s[int(i)]
ref(s::String, x::Real) = s[iround(x)]
ref{T<:Integer}(s::String, r::Range1{T}) = s[int(first(r)):int(last(r))]
ref(s::String, v::Vector) =
ref(s::String, v::AbstractVector) =
print_to_string(length(v), @thunk for i in v; print(s[i]); end)

symbol(s::String) = symbol(cstring(s))
Expand Down Expand Up @@ -773,33 +773,73 @@ rpad(s, n::Integer, p) = rpad(string(s), n, string(p))
lpad(s, n::Integer) = lpad(string(s), n, " ")
rpad(s, n::Integer) = rpad(string(s), n, " ")

# split on a single character in a collection
function split(s::String, delims, include_empty::Bool)
i = 1
i = start(s)
len = length(s)
strs = String[]
while true
tokstart = tokend = i
while !done(s,i)
(c,i) = next(s,i)
c,i = next(s,i)
if contains(delims, c)
break
end
tokend = i
end
tok = s[tokstart:(tokend-1)]
if include_empty || !isempty(tok)
push(strs, tok)
if include_empty || tokstart < tokend
push(strs, s[tokstart:tokend-1])
end
if !((i <= len) || (i==len+1 && tokend!=i))
if !(i <= len || i==len+1 && tokend!=i)
break
end
end
strs
return strs
end

split(s::String) = split(s, (' ','\t','\n','\v','\f','\r'), false)
split(s::String, x) = split(s, x, true)

# split on a string literal
function split(s::String, delim::String, include_empty::Bool)
i = start(s)
len = length(s)
strs = String[]
jj = start(delim)
d1, jj = next(delim,jj)
tokstart = tokend = i
while !done(s,i)
c,i = next(s,i)
if c == d1
j = jj
matched = true
while !done(delim,j)
if done(s,i)
matched = false
break
end
c,i = next(s,i)
d,j = next(delim,j)
if c != d
matched = false
break
end
end
if matched
if include_empty || tokstart < tokend
push(strs, s[tokstart:tokend-1])
end
tokstart = i
end
end
tokend = i
end
if include_empty || tokstart < tokend
push(strs, s[tokstart:tokend-1])
end
return strs
end

function print_joined(strings, delim, last)
i = start(strings)
if done(strings,i)
Expand Down

0 comments on commit 7d45ea5

Please sign in to comment.