Skip to content

Commit 286e849

Browse files
committed
Fix up some array issues
1 parent 63f4a40 commit 286e849

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ for (type, _, _) in ABSTRACT_QUANTITY_TYPES, (type2, _, _) in ABSTRACT_QUANTITY_
320320
end
321321

322322
Base.convert(::Type{D}, d::D) where {R,D<:AbstractDimensions{R}} = d
323-
Base.convert(::Type{D}, d::AbstractDimensions) where {D<:AbstractDimensions} = D(d)
323+
Base.convert(::Type{D}, d::AbstractDimensions{R}) where {R,D<:AbstractDimensions} = with_type_parameters(D, R)(d)
324324
Base.convert(::Type{D}, d::AbstractDimensions) where {R,D<:AbstractDimensions{R}} = D(d)
325325

326326
Base.copy(d::D) where {D<:AbstractDimensions} = map_dimensions(copy, d)

test/unittests.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ end
697697
# Actually expands to:
698698
@test string(dimension(us"Constants.h")) == "h_constant"
699699

700-
# So the numerical value is different from other constants:
701-
@test ustrip(us"Constants.h") == ustrip(u"Constants.h")
700+
# Constants have different numerical value from non-symbolic one:
701+
@test ustrip(us"Constants.h") != ustrip(u"Constants.h")
702702
@test ustrip(us"Constants.au") != ustrip(u"Constants.au")
703703

704704
# Test conversion
@@ -912,10 +912,10 @@ end
912912
@test x[5] == Q(5, length=1, time=-1)
913913

914914
y = randn(32)
915-
@test ustrip(QuantityArray(y, Q(u"m"))) == y
915+
@test ustrip(QuantityArray(y, Q(u"m"))) y
916916

917917
f_square(v) = v^2 * 1.5 - v^2
918-
@test sum(f_square.(QuantityArray(y, Q(u"m")))) == sum(f_square.(y) .* Q(u"m^2"))
918+
@test sum(f_square.(QuantityArray(y, Q(u"m")))) sum(f_square.(y) .* Q(u"m^2"))
919919

920920
y_q = QuantityArray(y, Q(u"m * cd / s"))
921921
@test typeof(f_square.(y_q)) == typeof(y_q)
@@ -1057,7 +1057,7 @@ end
10571057
y_q = QuantityArray(y, Q(u"m"))
10581058

10591059
f4(v) = v^4 * 0.3
1060-
@test sum(f4.(QuantityArray(y, Q(u"m")))) == sum(f4.(y) .* Q(u"m^4"))
1060+
@test sum(f4.(QuantityArray(y, Q(u"m")))) sum(f4.(y) .* Q(u"m^4"))
10611061

10621062
f4v(v) = f4.(v)
10631063
@inferred f4v(y_q)
@@ -1600,9 +1600,8 @@ end
16001600
y = 5randn(10) .- 2.5
16011601
for Q in (RealQuantity, Quantity, GenericQuantity), D in (Dimensions, SymbolicDimensions), f in functions
16021602
ground_truth = @eval $f.($x, $y)
1603-
dim = convert(D, dimension(u"m/s"))
1604-
qx_dimensions = [Q(xi, dim) for xi in x]
1605-
qy_dimensions = [Q(yi, dim) for yi in y]
1603+
qx_dimensions = [with_type_parameters(Q, Float64, D)(xi, dim) for xi in x]
1604+
qy_dimensions = [with_type_parameters(Q, Float64, D)(yi, dim) for yi in y]
16061605
@eval @test all($f.($qx_dimensions, $qy_dimensions) .== $ground_truth)
16071606
if f in (:isequal, :(==))
16081607
# These include a dimension check in the result, rather than

0 commit comments

Comments
 (0)