Browse files

a bit of library cleanup

we don't use == to compare whole arrays anywhere else, so it's confusing to use it in assert
  • Loading branch information...
1 parent a811699 commit 1945dcfc72be03d9430c944705a3de6be57b7ca0 @JeffBezanson JeffBezanson committed Apr 17, 2012
View
2 base/abstractarray.jl
@@ -56,8 +56,6 @@ similar{T}(a::AbstractArray{T}, dims::Dims) = similar(a, T, dims)
similar{T}(a::AbstractArray{T}, dims::Int...) = similar(a, T, dims)
similar (a::AbstractArray, T, dims::Int...) = similar(a, T, dims)
-empty(a::AbstractArray) = similar(a, 0)
-
function reshape(a::AbstractArray, dims::Dims)
if prod(dims) != numel(a)
error("reshape: invalid dimensions")
View
5 base/client.jl
@@ -15,9 +15,6 @@ function _jl_answer_color()
"\033[1m\033[34m"
end
-_jl_color_available() =
- success(`tput setaf 0`) || has(ENV, "TERM") && matches(r"^xterm", ENV["TERM"])
-
_jl_banner() = print(_jl_have_color ? _jl_banner_color : _jl_banner_plain)
function repl_callback(ast::ANY, show_value)
@@ -212,7 +209,7 @@ function _start()
(quiet,repl) = process_options(ARGS)
if repl
- global _jl_have_color = _jl_color_available()
+ global _jl_have_color = success(`tput setaf 0`) || has(ENV, "TERM") && matches(r"^xterm", ENV["TERM"])
if !quiet
_jl_banner()
end
View
6 base/error.jl
@@ -17,11 +17,9 @@ system_error(p, b::Bool) = b ? error(SystemError(string(p))) : nothing
## assertion functions and macros ##
-assert_test(b::Bool) = b
-assert_test(b::AbstractArray{Bool}) = all(b)
assert(x) = assert(x,'?')
-assert(x,labl) = assert_test(x) ? nothing : error("assertion failed: ", labl)
+assert(x,labl) = x ? nothing : error("assertion failed: ", labl)
macro assert(ex)
- :(assert_test($ex) ? nothing : error("assertion failed: ", $string(ex)))
+ :(($ex) ? nothing : error("assertion failed: ", $string(ex)))
end
View
12 base/inference.jl
@@ -1604,16 +1604,6 @@ function finfer(f, types)
tree
end
-tfunc(f,t) = (getmethods(f,t)[1][3]).tfunc
+#tfunc(f,t) = (getmethods(f,t)[1][3]).tfunc
ccall(:jl_enable_inference, Void, ())
-
-# stuff for testing
-
-# T=typevar(:T)
-# S=typevar(:S)
-# R=typevar(:R)
-# a=typevar(:a)
-# b=typevar(:b)
-# c=typevar(:c)
-# d=typevar(:d)
View
4 base/iterator.jl
@@ -1,7 +1,7 @@
# enumerate
-type Enumerate
- itr
+type Enumerate{I}
+ itr::I
end
enumerate(itr) = Enumerate(itr)
View
18 base/multi.jl
@@ -1531,18 +1531,18 @@ end
# A=randn(800,800);A=A*A';
# pmap(fv, {A,A,A})
-all2all() = at_each(hello_from, myid())
+#all2all() = at_each(hello_from, myid())
-hello_from(i) = print("message from $i to $(myid())\n")
+#hello_from(i) = print("message from $i to $(myid())\n")
# monte carlo estimate of pi
-function buffon(niter)
- nc =
- @parallel (+) for i=1:niter
- rand() <= sin(rand()*pi/2) ? 1 : 0
- end
- 2/(nc/niter)
-end
+# function buffon(niter)
+# nc =
+# @parallel (+) for i=1:niter
+# rand() <= sin(rand()*pi/2) ? 1 : 0
+# end
+# 2/(nc/niter)
+# end
## event processing, I/O and work scheduling ##
View
1 base/operators.jl
@@ -96,7 +96,6 @@ oftype{T}(x::T,c) = convert(T,c)
zero(x) = oftype(x,0)
one(x) = oftype(x,1)
-two(x) = oftype(x,2)
sizeof(T::Type) = error(strcat("size of type ",T," unknown"))
sizeof(T::BitsKind) = div(T.nbits,8)
View
1 base/sysimg.jl
@@ -122,7 +122,6 @@ compile_hint(isempty, (Array{WorkItem,1},))
compile_hint(ref, (HashTable{Any,Any}, Int32))
compile_hint(event_loop, (Bool,))
compile_hint(_start, ())
-compile_hint(_jl_color_available, ())
compile_hint(process_options, (Array{Any,1},))
compile_hint(run_repl, ())
compile_hint(anyp, (Function, Array{Any,1}))
View
2 base/tuple.jl
@@ -22,8 +22,6 @@ ntuple(n::Integer, f) = n<=0 ? () :
n==5 ? (f(1),f(2),f(3),f(4),f(5),) :
tuple(ntuple(n-2,f)..., f(n-1), f(n))
-accumtuple(t::Tuple, r, i, step) = ntuple(length(r), n->t[i+step*(n-1)])
-
# 0 argument function
map(f) = f()
# 1 argument function
View
2 examples/rmt/chapter2.jl
@@ -1,6 +1,6 @@
# code 2.5
function patiencesort(p)
- piles = empty(p)
+ piles = similar(p, 0)
for i = 1:length(p)
idx = 1+sum(p[i]>piles)
if idx > length(piles)
View
1 src/builtin_proto.h
@@ -35,7 +35,6 @@ JL_CALLABLE(jl_f_new_type_constructor);
JL_CALLABLE(jl_f_new_tag_type);
JL_CALLABLE(jl_f_new_tag_type_super);
JL_CALLABLE(jl_f_new_bits_type);
-JL_CALLABLE(jl_f_def_macro);
JL_CALLABLE(jl_f_typevar);
JL_CALLABLE(jl_f_union);
JL_CALLABLE(jl_f_methodexists);
View
16 src/builtins.c
@@ -1017,21 +1017,6 @@ JL_CALLABLE(jl_f_new_bits_type)
extern int jl_boot_file_loaded;
-JL_CALLABLE(jl_f_def_macro)
-{
- jl_sym_t *nm = (jl_sym_t*)args[0];
- assert(jl_is_symbol(nm));
- jl_function_t *f = (jl_function_t*)args[1];
- assert(jl_is_function(f));
- if (jl_boot_file_loaded &&
- f->linfo && f->linfo->ast && jl_is_expr(f->linfo->ast)) {
- jl_lambda_info_t *li = f->linfo;
- li->ast = jl_compress_ast(li, li->ast);
- }
- jl_set_expander(jl_current_module, nm, f);
- return (jl_value_t*)jl_nothing;
-}
-
JL_CALLABLE(jl_f_typevar)
{
if (nargs < 1 || nargs > 3) {
@@ -1217,7 +1202,6 @@ void jl_init_primitives(void)
add_builtin_func("new_tag_type", jl_f_new_tag_type);
add_builtin_func("new_tag_type_super", jl_f_new_tag_type_super);
add_builtin_func("new_bits_type", jl_f_new_bits_type);
- add_builtin_func("def_macro", jl_f_def_macro);
// builtin types
add_builtin("Any", (jl_value_t*)jl_any_type);
View
3 src/dump.c
@@ -1055,8 +1055,7 @@ void jl_init_serializer(void)
jl_trampoline, jl_f_new_struct_type,
jl_f_new_struct_fields, jl_f_new_type_constructor,
jl_f_new_tag_type, jl_f_new_tag_type_super,
- jl_f_new_bits_type, jl_f_def_macro,
- jl_f_typevar, jl_f_union,
+ jl_f_new_bits_type, jl_f_typevar, jl_f_union,
jl_f_methodexists, jl_f_applicable,
jl_f_invoke, jl_apply_generic,
jl_unprotect_stack, jl_f_task,
View
15 src/interpreter.c
@@ -60,6 +60,8 @@ jl_value_t *jl_eval_global_var(jl_module_t *m, jl_sym_t *e)
return v;
}
+extern int jl_boot_file_loaded;
+
static jl_value_t *eval(jl_value_t *e, jl_value_t **locals, size_t nl)
{
if (jl_is_symbol(e)) {
@@ -177,6 +179,19 @@ static jl_value_t *eval(jl_value_t *e, jl_value_t **locals, size_t nl)
jl_declare_constant(b);
return (jl_value_t*)jl_nothing;
}
+ else if (ex->head == macro_sym) {
+ jl_sym_t *nm = (jl_sym_t*)args[0];
+ assert(jl_is_symbol(nm));
+ jl_function_t *f = (jl_function_t*)eval(args[1], locals, nl);
+ assert(jl_is_function(f));
+ if (jl_boot_file_loaded &&
+ f->linfo && f->linfo->ast && jl_is_expr(f->linfo->ast)) {
+ jl_lambda_info_t *li = f->linfo;
+ li->ast = jl_compress_ast(li, li->ast);
+ }
+ jl_set_expander(jl_current_module, nm, f);
+ return (jl_value_t*)jl_nothing;
+ }
else if (ex->head == error_sym) {
jl_errorf("syntax error: %s", jl_string_data(args[0]));
}
View
4 src/julia-syntax.scm
@@ -561,8 +561,8 @@
;; macro definition
(pattern-lambda (macro (call name . argl) body)
- `(call (top def_macro) (quote ,name)
- (-> (tuple ,@argl) ,body)))
+ `(macro ,name
+ (-> (tuple ,@argl) ,body)))
;; type definition
(pattern-lambda (type sig (block . fields))
View
22 test/arrayops.jl
@@ -9,15 +9,15 @@ b = a+a
@assert length((1,)) == 1
@assert length((1,2)) == 2
-@assert 1+[1,2,3] == [2,3,4]
-@assert [1,2,3]+1 == [2,3,4]
-@assert 1-[1,2,3] == [0,-1,-2]
-@assert [1,2,3]-1 == [0,1,2]
+@assert isequal(1+[1,2,3], [2,3,4])
+@assert isequal([1,2,3]+1, [2,3,4])
+@assert isequal(1-[1,2,3], [0,-1,-2])
+@assert isequal([1,2,3]-1, [0,1,2])
-@assert 5*[1,2,3] == [5,10,15]
-@assert [1,2,3]*5 == [5,10,15]
-@assert 1/[1,2,5] == [1.0,0.5,0.2]
-@assert [1,2,3]/5 == [0.2,0.4,0.6]
+@assert isequal(5*[1,2,3], [5,10,15])
+@assert isequal([1,2,3]*5, [5,10,15])
+@assert isequal(1/[1,2,5], [1.0,0.5,0.2])
+@assert isequal([1,2,3]/5, [0.2,0.4,0.6])
a = ones(2,2)
a[1,1] = 1
@@ -61,8 +61,8 @@ v = pop(l)
@assert length(l)==2
# concatenation
-@assert [ones(2,2) 2*ones(2,1)] == [1 1 2; 1 1 2]
-@assert [ones(2,2), 2*ones(1,2)] == [1 1; 1 1; 2 2]
+@assert isequal([ones(2,2) 2*ones(2,1)], [1 1 2; 1 1 2])
+@assert isequal([ones(2,2), 2*ones(1,2)], [1 1; 1 1; 2 2])
# "end"
X = [ i+2j | i=1:5, j=1:5 ]
@@ -135,7 +135,7 @@ for i=1:16
z[i] = i
end
-@assert sum(z) == sum(z,(1,2,3,4)) == 136
+@assert sum(z) == sum(z,(1,2,3,4))[1] == 136
v = cell(2,2,1,1)
v[1,1,1,1] = 28.0
View
8 test/bitarray.jl
@@ -52,11 +52,11 @@ i1 = randi(2, n1, n2) - 1
@check_bit_operation numel Int (b1,)
@check_bit_operation size (Int...) (b1,)
-@assert bitunpack(bitones(T, n1, n2)) == ones(T, n1, n2)
-@assert bitunpack(bitzeros(T, n1, n2)) == zeros(T, n1, n2)
+@assert isequal(bitunpack(bitones(T, n1, n2)), ones(T, n1, n2))
+@assert isequal(bitunpack(bitzeros(T, n1, n2)), zeros(T, n1, n2))
-@assert fill(b1, one(T)) == bitones(T, size(b1))
-@assert fill(b1, zero(T)) == bitzeros(T, size(b1))
+@assert isequal(fill(b1, one(T)), bitones(T, size(b1)))
+@assert isequal(fill(b1, zero(T)), bitzeros(T, size(b1)))
@timesofar "utils"
View
4 test/corelib.jl
@@ -28,8 +28,8 @@ r = [5:-1:1]
X = [ i+2j | i=1:5, j=1:5 ]
@assert X[2,3] == 8
@assert X[4,5] == 14
-@assert ones(2,3) * ones(2,3)' == [3. 3.; 3. 3.] #'
-@assert [ [1,2] | i=1:2, : ] == [1 2; 1 2]
+@assert isequal(ones(2,3) * ones(2,3)', [3. 3.; 3. 3.])
+@assert isequal([ [1,2] | i=1:2, : ], [1 2; 1 2])
# where element type is a Union. try to confuse type inference.
foo32_64(x) = (x<2) ? int32(x) : int64(x)
boo32_64() = [ foo32_64(i) | i=1:2 ]
View
12 test/functional.jl
@@ -1,7 +1,7 @@
# tests related to functional programming functions and styles
# map -- array.jl
-@assert map((x)->"$x"[end:end], [9:11]) == ["9", "0", "1"]
+@assert isequal(map((x)->"$x"[end:end], [9:11]), ["9", "0", "1"])
# TODO: @assert map_to()
# maps of tuples (formerly in test/core.jl) -- tuple.jl
@@ -23,9 +23,7 @@
@assert mapreduce((x,y)->"($x+$y)", (x)->x[1:3], ["abcd", "efgh", "01234"]) == "((abc+efg)+012)"
# filter -- array.jl
-@assert filter(x->(x>1), [0 1 2 3 2 1 0]) == [2, 3, 2]
-# TODO: @assert_throws_error filter(x->x+1, [0 1 2 3 2 1 0]) == [2, 3, 2]
-@assert filter(x->(x>10), [0 1 2 3 2 1 0]) == []
-@assert filter((ss)->length(ss)==3, ["abcd", "efg", "hij", "klmn", "opq"]) == ["efg", "hij", "opq"]
-
-
+@assert isequal(filter(x->(x>1), [0 1 2 3 2 1 0]), [2, 3, 2])
+# TODO: @assert_fails isequal(filter(x->x+1, [0 1 2 3 2 1 0]), [2, 3, 2])
+@assert isequal(filter(x->(x>10), [0 1 2 3 2 1 0]), [])
+@assert isequal(filter((ss)->length(ss)==3, ["abcd", "efg", "hij", "klmn", "opq"]), ["efg", "hij", "opq"])
View
4 test/perf/perf.jl
@@ -33,13 +33,13 @@ end
## array constructors ##
-@assert ones(200,200) == 1
+@assert all(ones(200,200) == 1)
# @timeit ones(200,200) "ones"
## matmul and transpose ##
A = ones(200,200)
-@assert A*A' == 200
+@assert all(A*A' == 200)
# @timeit A*A' "AtA"
## mandelbrot set: complex arithmetic and comprehensions ##
View
14 test/sparse.jl
@@ -8,37 +8,37 @@ se33 = speye(3)
# check mixed sparse-dense matrix operations
do33 = ones(3)
-@assert se33 \ do33 == do33
+@assert isequal(se33 \ do33, do33)
# check horiz concatenation
-@assert [se33 se33] == sparse([1, 2, 3, 1, 2, 3], [1, 2, 3, 4, 5, 6], ones(6))
+@assert all([se33 se33] == sparse([1, 2, 3, 1, 2, 3], [1, 2, 3, 4, 5, 6], ones(6)))
# check vert concatenation
-@assert [se33; se33] == sparse([1, 4, 2, 5, 3, 6], [1, 1, 2, 2, 3, 3], ones(6))
+@assert all([se33; se33] == sparse([1, 4, 2, 5, 3, 6], [1, 1, 2, 2, 3, 3], ones(6)))
# check h+v concatenation
se44 = speye(4)
sz42 = spzeros(4, 2)
sz41 = spzeros(4, 1)
sz34 = spzeros(3, 4)
se77 = speye(7)
-@assert [se44 sz42 sz41; sz34 se33] == se77
+@assert all([se44 sz42 sz41; sz34 se33] == se77)
# check concatenation promotion
sz41_f32 = spzeros(Float32, 4, 1)
se33_i32 = speye(Int32, 3, 3)
-@assert [se44 sz42 sz41_f32; sz34 se33_i32] == se77
+@assert all([se44 sz42 sz41_f32; sz34 se33_i32] == se77)
# check mixed sparse-dense concatenation
sz33 = spzeros(3)
de33 = eye(3)
-@assert [se33 de33; sz33 se33] == full([se33 se33; sz33 se33 ])
+@assert all([se33 de33; sz33 se33] == full([se33 se33; sz33 se33 ]))
# check splicing + concatenation on
# random instances, with nested vcat
# (also side-checks sparse ref, which uses
# sparse multiplication)
for i = 1 : 10
a = sprand(5, 4, 0.5)
- @assert [a[1:2,1:2] a[1:2,3:4]; a[3:5,1] [a[3:4,2:4]; a[5,2:4]]] == a
+ @assert all([a[1:2,1:2] a[1:2,3:4]; a[3:5,1] [a[3:4,2:4]; a[5,2:4]]] == a)
end

0 comments on commit 1945dcf

Please sign in to comment.