Skip to content

Commit ade74a7

Browse files
committed
fixing last value of for loop
for i=a:b should be the same as R=a:b; for i=R need to change some loops in eig/eigs that modify the loop variable restoring behavior of let
1 parent 2b5e6d1 commit ade74a7

File tree

7 files changed

+35
-20
lines changed

7 files changed

+35
-20
lines changed

j/io.j

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ function del_all(s::FDSet)
261261
s
262262
end
263263

264-
let tv = Array(Uint8, long(ccall(:jl_sizeof_timeval, Int32, ())))
264+
begin
265+
local tv = Array(Uint8, long(ccall(:jl_sizeof_timeval, Int32, ())))
265266
global select_read
266267
function select_read(readfds::FDSet, timeout::Real)
267268
if timeout == Inf

j/linalg_arpack.j

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,16 @@ function eigs{T}(A::AbstractMatrix{T}, k::Int, evtype::ASCIIString)
232232
return (d, v[1:n, 1:nev])
233233
else
234234
evec = complex(zeros(T, n, nev+1), zeros(T, n, nev+1))
235-
for j=1:nev
235+
j = 1
236+
while j <= nev
236237
if di[j] == 0.0
237238
evec[:,j] = v[:,j]
238239
else
239240
evec[:,j] = v[:,j] + im*v[:,j+1]
240241
evec[:,j+1] = v[:,j] - im*v[:,j+1]
241242
j += 1
242243
end
244+
j += 1
243245
end
244246
return (complex(dr[1:nev],di[1:nev]), evec[1:n, 1:nev])
245247
end

j/linalg_lapack.j

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,16 @@ function eig{T<:Union(Float64,Float32,Complex128,Complex64)}(A::Matrix{T})
416416
return (W, VR)
417417
else
418418
evec = complex(zeros(T, n, n), zeros(T, n, n))
419-
for j=1:n
419+
j = 1
420+
while j <= n
420421
if WI[j] == 0.0
421422
evec[:,j] = VR[:,j]
422423
else
423424
evec[:,j] = VR[:,j] + im*VR[:,j+1]
424425
evec[:,j+1] = VR[:,j] - im*VR[:,j+1]
425426
j += 1
426427
end
428+
j += 1
427429
end
428430
return (complex(WR, WI), evec)
429431
end

j/math_libm.j

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ ldexp(x::Float32,e::Int32) = ccall(dlsym(libfdm, :ldexpf), Float32, (Float32,Int
108108
# TODO: vectorize does not do the right thing for these argument types
109109
#@vectorize_2arg Real ldexp
110110

111-
let exp::Array{Int32,1} = zeros(Int32,1)
111+
begin
112+
local exp::Array{Int32,1} = zeros(Int32,1)
112113
global frexp
113114
function frexp(x::Float64)
114115
s = ccall(dlsym(libfdm,:frexp), Float64, (Float64, Ptr{Int32}), x, exp)

j/string.j

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ hex(n::Union(Int,Float), l::Int) = lpad(hex(n), l, '0')
800800

801801
## string to float functions ##
802802

803-
let tmp::Array{Ptr{Uint8},1} = Array(Ptr{Uint8},1)
803+
begin
804+
local tmp::Array{Ptr{Uint8},1} = Array(Ptr{Uint8},1)
804805
global float64, float32
805806
function float64(s::String)
806807
s = cstring(s)

src/julia-syntax.scm

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,20 @@
460460
;; let
461461
(pattern-lambda (let ex . binds)
462462
(let loop ((binds binds)
463+
(args ())
464+
(inits ())
463465
(locls ())
464466
(stmts ()))
465467
(if (null? binds)
466-
`(call (-> (tuple)
468+
`(call (-> (tuple ,@args)
467469
(block (local (vars ,@locls))
468470
,@stmts
469471
,ex))
470-
)
472+
,@inits)
471473
(cond
472474
((or (symbol? (car binds)) (decl? (car binds)))
473475
;; just symbol -> add local
474-
(loop (cdr binds)
476+
(loop (cdr binds) args inits
475477
(cons (car binds) locls)
476478
stmts))
477479
((and (length= (car binds) 3)
@@ -480,17 +482,20 @@
480482
(cond
481483
((or (symbol? (cadar binds))
482484
(decl? (cadar binds)))
483-
;; a=b -> add local and initializer
485+
;; a=b -> add argument
484486
(loop (cdr binds)
485-
(cons (cadar binds) locls)
486-
(cons `(= ,(decl-var (cadar binds))
487+
(cons (cadar binds) args)
488+
(cons (caddar binds) inits)
489+
locls stmts))
490+
#;(cons (cadar binds) locls)
491+
#;(cons `(= ,(decl-var (cadar binds))
487492
,(caddar binds))
488-
stmts)))
493+
stmts);))
489494
((and (pair? (cadar binds))
490495
(eq? (caadar binds) 'call))
491496
;; f()=c
492497
(let ((asgn (cadr (julia-expand0 (car binds)))))
493-
(loop (cdr binds)
498+
(loop (cdr binds) args inits
494499
(cons (cadr asgn) locls)
495500
(cons asgn stmts))))
496501
(else (error "invalid let syntax"))))
@@ -738,22 +743,24 @@
738743
(break-block loop-cont
739744
,body)
740745
(= ,cnt (call + 1 ,cnt))))))))
741-
(let ((lim (if (number? b) b (gensy))))
746+
(let ((cnt (gensy))
747+
(lim (if (number? b) b (gensy))))
742748
`(scope-block
743749
(block
744-
(= ,var ,a)
750+
(= ,cnt ,a)
745751
,@(if (eq? lim b) '() `((= ,lim ,b)))
746752
(break-block loop-exit
747-
(_while (call <= ,var ,lim)
753+
(_while (call <= ,cnt ,lim)
748754
(block
755+
(= ,var ,cnt)
749756
(break-block loop-cont
750757
,body)
751-
(= ,var (call +
758+
(= ,cnt (call +
752759
(call (top convert)
753760
(call (top typeof)
754-
,var)
761+
,cnt)
755762
1)
756-
,var)))))))))))
763+
,cnt)))))))))))
757764

758765
; for loop over arbitrary vectors
759766
(pattern-lambda

test/perf.j

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ function mandel(z::Complex)
5050
c = z
5151
for n=0:79
5252
if abs(z)>2
53+
n -= 1
5354
break
5455
end
5556
z = z^2+c
5657
end
57-
n
58+
n+1
5859
end
5960

6061
mandelperf() = [ mandel(complex(r,i)) | r=-2.0:.1:0.5, i=-1.:.1:1. ]

0 commit comments

Comments
 (0)