Skip to content

Commit

Permalink
use length() everywhere, make numel() an alias
Browse files Browse the repository at this point in the history
subsumes request #454
  • Loading branch information
JeffBezanson committed Feb 24, 2012
1 parent d2bbaa5 commit d1ba897
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 13 deletions.
3 changes: 1 addition & 2 deletions j/abstractarray.j
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ typealias RangeIndex Union(Int, Range{Int}, Range1{Int})
size{T,n}(t::AbstractArray{T,n}, d) = (d>n ? 1 : size(t)[d])
eltype{T,n}(::AbstractArray{T,n}) = T
ndims{T,n}(::AbstractArray{T,n}) = n
numel(t::AbstractArray) = prod(size(t))
length(a::AbstractArray) = numel(a)
length(t::AbstractArray) = prod(size(t))
first(a::AbstractArray) = a[1]
last(a::AbstractArray) = a[end]

Expand Down
2 changes: 1 addition & 1 deletion j/array.j
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typealias StridedVecOrMat{T} Union(StridedVector{T}, StridedMatrix{T})
size(a::Array) = arraysize(a)
size(a::Array, d) = arraysize(a, d)
size(a::Matrix) = (arraysize(a,1), arraysize(a,2))
numel(a::Array) = arraylen(a)
length(a::Array) = arraylen(a)

## copy ##

Expand Down
2 changes: 1 addition & 1 deletion j/base.j
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function append_any(xs...)
# exact function.
n = 0
for x = xs
n += numel(x)
n += length(x)
end
out = Array(Any, n)
i = 1
Expand Down
2 changes: 1 addition & 1 deletion j/intset.j
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function pop(s::IntSet)
n
end

numel(s::IntSet) =
length(s::IntSet) =
int(ccall(:bitvector_count, Uint64, (Ptr{Uint32}, Uint64, Uint64),
s.bits, uint64(0), uint64(s.limit)))

Expand Down
1 change: 0 additions & 1 deletion j/number.j
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const islogical = isbool

size(x::Number) = ()
ndims(x::Number) = 0
numel(x::Number) = 1
length(x::Number) = 1
ref(x::Number) = x

Expand Down
2 changes: 1 addition & 1 deletion j/range.j
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ colon(start::Real, stop::Real) = colon(promote(start, stop)...)
similar(r::Ranges, T::Type, dims::Dims) = Array(T, dims)

length(r::Ranges) = r.len
const numel = length
size(r::Ranges) = (r.len,)
numel(r::Ranges) = r.len
isempty(r::Ranges) = r.len==0
first(r::Ranges) = r.start
last{T}(r::Range{T}) = r.start + oftype(T,r.len-1)*step(r)
Expand Down
2 changes: 1 addition & 1 deletion j/set.j
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Set{T}(x::T...) = Set{T}(x...)
show(s::Set) = (show(typeof(s)); show_comma_array(s,'(',')'))

isempty(s::Set) = isempty(s.hash)
numel(s::Set) = numel(s.hash)
length(s::Set) = length(s.hash)
eltype{T}(s::Set{T}) = T

has(s::Set, x) = has(s.hash, x)
Expand Down
1 change: 0 additions & 1 deletion j/sparse.j
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,6 @@ end
SparseAccumulator(s::Integer) = SparseAccumulator(Float64, Int32, s)

length(S::SparseAccumulator) = length(S.vals)
numel(S::SparseAccumulator) = S.nvals

# store spa and reset
function _jl_spa_store_reset{T}(S::SparseAccumulator{T}, col, colptr, rowval, nzval)
Expand Down
1 change: 0 additions & 1 deletion j/string.j
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ next(s::String, i::Integer) = next(s,int(i))

start(s::String) = 1
done(s::String,i) = (i > length(s))
numel(s::String) = length(s)
isempty(s::String) = done(s,start(s))
ref(s::String, i::Int) = next(s,i)[1]
ref(s::String, i::Integer) = s[int(i)]
Expand Down
4 changes: 2 additions & 2 deletions j/table.j
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function assign{K,V}(h::HashTable{K,V}, v, key)
sz = length(h.keys)
if numel(h.deleted) >= ((3*sz)>>2)
if length(h.deleted) >= ((3*sz)>>2)
rehash(h, sz)
end
Expand Down Expand Up @@ -305,7 +305,7 @@ next(t::HashTable, i) = ((n, nxt) = next(t.used, i);
skip_deleted(t.used,t.deleted,nxt)))
isempty(t::HashTable) = done(t, start(t))
numel(t::HashTable) = numel(t.used)-numel(t.deleted)
length(t::HashTable) = length(t.used)-length(t.deleted)
function add_weak_key(t::HashTable, k, v)
if is(t.deleter, identity)
Expand Down
1 change: 0 additions & 1 deletion j/tuple.j
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## indexing ##

length(t::Tuple) = tuplelen(t)
numel (t::Tuple) = tuplelen(t)
size(t::Tuple, d) = d==1 ? tuplelen(t) : error("invalid tuple dimension")
ref(t::Tuple, i::Int) = tupleref(t, i)
ref(t::Tuple, i::Integer) = tupleref(t, int(i))
Expand Down

0 comments on commit d1ba897

Please sign in to comment.