2525creates a view of the array `A` that applies `f` to every element of
2626`A`. The view is read-only (you can get values but not set them).
2727"""
28- mappedarray {T,N} (f, data:: AbstractArray{T,N} ) = ReadonlyMappedArray {typeof(f(one(T ))),N,typeof(data),typeof(f)} (f, data)
28+ mappedarray {T,N} (f, data:: AbstractArray{T,N} ) = ReadonlyMappedArray {typeof(f(testvalue(data ))),N,typeof(data),typeof(f)} (f, data)
2929
3030"""
3131 mappedarray((f, finv), A)
@@ -36,7 +36,7 @@ the view and, correspondingly, the values in `A`.
3636"""
3737function mappedarray {T,N} (f_finv:: Tuple{Any,Any} , data:: AbstractArray{T,N} )
3838 f, finv = f_finv
39- MappedArray {typeof(f(one(T ))),N,typeof(data),typeof(f),typeof(finv)} (f, finv, data)
39+ MappedArray {typeof(f(testvalue(data ))),N,typeof(data),typeof(f),typeof(finv)} (f, finv, data)
4040end
4141
4242"""
@@ -60,4 +60,11 @@ parenttype{T,N,A,F,Finv}(::Type{MappedArray{T,N,A,F,Finv}}) = A
6060@propagate_inbounds Base. setindex! {T} (A:: MappedArray{T} , val:: T , i:: Int... ) = A. data[i... ] = A. finv (val)
6161@inline Base. setindex! {T} (A:: MappedArray{T} , val, i:: Int... ) = setindex! (A, convert (T, val), i... )
6262
63+ function testvalue (data)
64+ if ! isempty (data)
65+ return first (data)
66+ end
67+ zero (eltype (data))
68+ end
69+
6370end # module
0 commit comments