Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Commit d9ad970

Browse files
committed
Fix #76
Note that I made AbstractDataArray inherit from StoredArray instead of AbstractArray, since both DataArray and PooledDataArray are StoredArrays. DataArray should probably inherit from DenseArray, and the inheritance should probably be on those types and not AbstractDataArray, but we don't have multiple inheritance, so this seems like the way to go for now.
1 parent d0a0b3a commit d9ad970

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/abstractdataarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' An AbstractDataArray is an Array whose entries can take on
44
#' values of type `T` or the value `NA`.
5-
abstract AbstractDataArray{T, N} <: AbstractArray{T, N}
5+
abstract AbstractDataArray{T, N} <: StoredArray{T, N}
66

77
#' @description
88
#'

src/operators.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,9 @@ for f in unary_operators
364364
@eval $(f)(d::NAtype) = NA
365365
end
366366

367-
# Unary operators, DataArrays. Definitions in base should be adequate
368-
# for AbstractDataArrays. These are just optimizations
369-
Base.(:!)(d::DataArray{Bool}) = DataArray(!d.data, copy(d.na))
370-
Base.(:-)(d::DataArray) = DataArray(-d.data, copy(d.na))
367+
# Unary operators, DataArrays.
368+
@dataarray_unary Base.(:(-)) Any T
369+
@dataarray_unary Base.(:(!)) Bool T
371370

372371
# Treat ctranspose and * in a special way
373372
for (f, elf) in ((:(Base.ctranspose), :conj), (:(Base.transpose), :identity))

test/operators.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,29 @@ module TestOperators
7070
end
7171

7272
# transpose and ctranpose on DataVectors and DataMatrices
73-
for a in ([1, 2, 3, 4], [1.0+1.0im, 2.0-2.0im, 3.0+3.0im, 4.0-4.0im],
74-
[1 2; 3 4], [1.0+1.0im 2.0-2.0im; 3.0+3.0im 4.0-4.0im])
75-
end
7673
for (da, dat) in ((@data([5, 2, 3, 4]), @data([5 2 3 4])),
7774
(@data([1.0+1.0im, 5.0, 3.0+3.0im, 4.0-4.0im]), @data([1.0+1.0im 5.0 3.0+3.0im 4.0-4.0im])),
7875
(@data([1 2; 5 4]), @data([1 5; 2 4])),
7976
(@data([1.0+1.0im 2.0-2.0im; 3.0+3.0im 5.0]), @data([1.0+1.0im 3.0+3.0im; 2.0-2.0im 5.0])))
8077
# Test for both bits and non-bits types
8178
for da in (da, convert(DataArray{Number}, da))
82-
# No NA
83-
@test isequal(da.', dat)
84-
@test isequal(da', conj(dat))
85-
86-
# With NA
87-
# XXX we should fix indexing so that vec isn't necessary
88-
da[vec(da .== 5)] = NA
89-
dat[vec(dat .== 5)] = NA
90-
# Make sure that NAs are undefined in the non-bits array
91-
da = conj(conj(da))
92-
@test isequal(da.', dat)
93-
@test isequal(da', conj(dat))
79+
let da = copy(da), dat = copy(dat)
80+
# No NA
81+
@test isequal(da.', dat)
82+
@test isequal(da', conj(dat))
83+
84+
# With NA
85+
# XXX we should fix indexing so that this isn't necessary
86+
for i = 1:length(da)
87+
da[i] == 5 && (da[i] = NA)
88+
dat[i] == 5 && (dat[i] = NA)
89+
end
90+
91+
# Make sure that NAs are undefined in the non-bits array
92+
da = conj(conj(da))
93+
@test isequal(da.', dat)
94+
@test isequal(da', conj(dat))
95+
end
9496
end
9597
end
9698

0 commit comments

Comments
 (0)