@@ -259,62 +259,23 @@ end
259
259
_getproperty (data, Val {name} ())
260
260
end
261
261
262
- # Base.@propagate_inbounds function Base.getproperty(
263
- # data::AbstractData{S},
264
- # i::Integer,
265
- # ) where {S}
266
- # array = parent(data)
267
- # T = eltype(array)
268
- # SS = fieldtype(S, i)
269
- # offset = fieldtypeoffset(T, S, i)
270
- # nbytes = typesize(T, SS)
271
- # fdim = field_dim(data)
272
- # Ipre = ntuple(i -> Colon(), Val(fdim - 1))
273
- # Ipost = ntuple(i -> Colon(), Val(ndims(data) - fdim))
274
- # dataview =
275
- # @inbounds view(array, Ipre..., (offset + 1):(offset + nbytes), Ipost...)
276
- # union_all(data){SS, Base.tail(type_params(data))...}(dataview)
277
- # end
278
-
279
262
Base. @propagate_inbounds function Base. getproperty (
280
263
data:: AbstractData{S} ,
281
264
i:: Integer ,
282
265
) where {S}
283
- generic_property_view (data, i)
284
- end
285
-
286
- # # In the past, we've sometimes needed a generated function
287
- # # for inference and constant propagation:
288
- # Base.@propagate_inbounds @generated function _property_view(
289
- # data::AD,
290
- # ::Val{Idx},
291
- # ) where {S, Idx, AD <: AbstractData{S}}
292
- # SS = fieldtype(S, Idx)
293
- # T = eltype(parent_array_type(AD))
294
- # offset = fieldtypeoffset(T, S, Val(Idx))
295
- # nbytes = typesize(T, SS)
296
- # fdim = field_dim(AD)
297
- # Ipre = ntuple(i -> Colon(), Val(fdim - 1))
298
- # Ipost = ntuple(i -> Colon(), Val(ndims(data) - fdim))
299
- # field_byterange = (offset + 1):(offset + nbytes)
300
- # return :($(union_all(AD)){$SS, $(Base.tail(type_params(AD)))...}(
301
- # @inbounds view(parent(data), $Ipre..., $field_byterange, $Ipost...)
302
- # ))
303
- # end
266
+ P = Base. tail (type_params (data))
267
+ SS = fieldtype (S, i)
268
+ return union_all (data){SS, P... }(generic_property_view (data, i))
269
+ end
304
270
305
271
@inline function generic_property_view (
306
272
data:: AbstractData{S} ,
307
273
i:: Integer ,
308
274
) where {S}
309
275
fa = parent (data)
310
276
T = eltype (fa)
311
- @show i
312
- @show S
313
- @show T
314
277
SS = fieldtype (S, i)
315
- @show SS
316
278
offset = fieldtypeoffset (T, S, i)
317
- @show offset
318
279
nbytes = typesize (T, SS)
319
280
field_byterange = (offset + 1 ): (offset + nbytes)
320
281
return FieldArray {field_dim(data)} (ntuple (jf -> parent (data). arrays[offset + jf], nbytes))
@@ -634,6 +595,7 @@ function DataF{S}(::Type{ArrayType}) where {S, ArrayType}
634
595
T = eltype (ArrayType)
635
596
DataF {S} (ArrayType (undef, typesize (T, S)))
636
597
end
598
+ DataF {S} (fa:: FieldArray ) where {S} = DataF {S, typeof(fa)} (fa)
637
599
638
600
function DataF (x:: T ) where {T}
639
601
if is_valid_basetype (Float64, T)
@@ -722,6 +684,8 @@ function IJF{S, Nij}(array::AbstractArray{T, 3}) where {S, Nij, T}
722
684
IJF {S, Nij, typeof(fa)} (fa)
723
685
end
724
686
687
+ IJF {S, Nij} (fa:: FieldArray ) where {S, Nij} = IJF {S, Nij, typeof(fa)} (fa)
688
+
725
689
function IJF {S, Nij} (:: Type{MArray} , :: Type{T} ) where {S, Nij, T}
726
690
Nf = typesize (T, S)
727
691
array = MArray {Tuple{Nij, Nij, Nf}, T, 3, Nij * Nij * Nf} (undef)
@@ -881,6 +845,8 @@ struct VF{S, Nv, FA <: FieldArray} <: DataColumn{S, Nv}
881
845
array:: FA
882
846
end
883
847
848
+ VF {S, Nv} (fa:: FieldArray ) where {S, Nv} = VF {S, Nv, typeof(fa)} (fa)
849
+
884
850
parent_array_type (:: Type{VF{S, Nv, A}} ) where {S, Nv, A} = parent_array_type (A)
885
851
886
852
function VF {S, Nv} (array:: AbstractArray{T, 2} ) where {S, Nv, T}
@@ -907,8 +873,8 @@ Base.lastindex(data::VF) = length(data)
907
873
908
874
nlevels (:: VF{S, Nv} ) where {S, Nv} = Nv
909
875
910
- Base. @propagate_inbounds Base. getproperty (data:: VF , i:: Integer ) =
911
- _property_view (data, Val (i) )
876
+ # Base.@propagate_inbounds Base.getproperty(data::VF, i::Integer) =
877
+ # generic_property_view (data, i )
912
878
913
879
@inline function Base. getindex (data:: VF{S, Nv} , I:: CartesianIndex ) where {S, Nv}
914
880
v = I. I[4 ]
@@ -1129,14 +1095,15 @@ end
1129
1095
# Note: construct the subarray view directly as optimizer fails in Base.to_indices (v1.7)
1130
1096
@inline function column (data:: VIFH{S, Nv, Ni, Nh} , i, h) where {S, Nv, Ni, Nh}
1131
1097
array = parent (data)
1132
- @boundscheck (1 <= i <= Ni && 1 <= h <= Nh) ||
1133
- throw (BoundsError (data, (i, h)))
1098
+ @boundscheck (1 <= i <= Ni && 1 <= h <= Nh) || throw (BoundsError (data, (i, h)))
1134
1099
Nf = ncomponents (data)
1135
- dataview = @inbounds SubArray (
1136
- array,
1137
- (Base. Slice (Base. OneTo (Nv)), i, Base. Slice (Base. OneTo (Nf)), h),
1138
- )
1139
- VF {S, Nv} (dataview)
1100
+ dataview = @inbounds ntuple (Nf) do f
1101
+ SubArray (
1102
+ array. arrays[f],
1103
+ (Base. Slice (Base. OneTo (Nv)), i, h),
1104
+ )
1105
+ end
1106
+ VF {S, Nv} (FieldArray {field_dim(VF)} (dataview))
1140
1107
end
1141
1108
1142
1109
@inline function column (
@@ -1449,6 +1416,25 @@ type parameters.
1449
1416
@inline farray_size (data:: VIJFH{S, Nv, Nij, Nh} ) where {S, Nv, Nij, Nh} = (Nv, Nij, Nij, ncomponents (data), Nh)
1450
1417
@inline farray_size (data:: VIFH{S, Nv, Ni, Nh} ) where {S, Nv, Ni, Nh} = (Nv, Ni, ncomponents (data), Nh)
1451
1418
1419
+ """
1420
+ float_type(data::AbstractData)
1421
+
1422
+ This is an internal function, please do not use outside of ClimaCore.
1423
+
1424
+ Returns the underlying float type of the backing array.
1425
+ """
1426
+ @inline float_type (:: Type{IJKFVH{S, Nij, Nk, Nv, Nh, FA}} ) where {S, Nij, Nk, Nv, Nh, FA} = eltype (FA)
1427
+ @inline float_type (:: Type{IJFH{S, Nij, Nh, FA}} ) where {S, Nij, Nh, FA} = eltype (FA)
1428
+ @inline float_type (:: Type{IFH{S, Ni, Nh, FA}} ) where {S, Ni, Nh, FA} = eltype (FA)
1429
+ @inline float_type (:: Type{DataF{S, FA}} ) where {S, FA} = eltype (FA)
1430
+ @inline float_type (:: Type{IJF{S, Nij, FA}} ) where {S, Nij, FA} = eltype (FA)
1431
+ @inline float_type (:: Type{IF{S, Ni, FA}} ) where {S, Ni, FA} = eltype (FA)
1432
+ @inline float_type (:: Type{VF{S, Nv, FA}} ) where {S, Nv, FA} = eltype (FA)
1433
+ @inline float_type (:: Type{VIJFH{S, Nv, Nij, Nh, FA}} ) where {S, Nv, Nij, Nh, FA} = eltype (FA)
1434
+ @inline float_type (:: Type{VIFH{S, Nv, Ni, Nh, FA}} ) where {S, Nv, Ni, Nh, FA} = eltype (FA)
1435
+ @inline float_type (:: Type{IH1JH2{S, Nij, A}} ) where {S, Nij, A} = eltype (A)
1436
+ @inline float_type (:: Type{IV1JH2{S, n1, Ni, A}} ) where {S, n1, Ni, A} = eltype (A)
1437
+
1452
1438
# Keep in sync with definition(s) in libs.
1453
1439
@inline slab_index (i, j) = CartesianIndex (i, j, 1 , 1 , 1 )
1454
1440
@inline slab_index (i) = CartesianIndex (i, 1 , 1 , 1 , 1 )
@@ -1548,21 +1534,4 @@ include("mapreduce.jl")
1548
1534
include (" non_extruded_broadcasted.jl" )
1549
1535
include (" has_uniform_datalayouts.jl" )
1550
1536
1551
-
1552
- float_type (
1553
- :: Type{IJKFVH{S, Nij, Nk, Nv, Nh, FA}} ,
1554
- ) where {S, Nij, Nk, Nv, Nh, FA} = eltype (FA)
1555
- float_type (:: Type{IJFH{S, Nij, Nh, FA}} ) where {S, Nij, Nh, FA} = eltype (FA)
1556
- float_type (:: Type{IFH{S, Ni, Nh, FA}} ) where {S, Ni, Nh, FA} = eltype (FA)
1557
- float_type (:: Type{DataF{S, FA}} ) where {S, FA} = eltype (FA)
1558
- float_type (:: Type{IJF{S, Nij, FA}} ) where {S, Nij, FA} = eltype (FA)
1559
- float_type (:: Type{IF{S, Ni, FA}} ) where {S, Ni, FA} = eltype (FA)
1560
- float_type (:: Type{VF{S, Nv, FA}} ) where {S, Nv, FA} = eltype (FA)
1561
- float_type (:: Type{VIJFH{S, Nv, Nij, Nh, FA}} ) where {S, Nv, Nij, Nh, FA} =
1562
- eltype (FA)
1563
- float_type (:: Type{VIFH{S, Nv, Ni, Nh, FA}} ) where {S, Nv, Ni, Nh, FA} =
1564
- eltype (FA)
1565
- float_type (:: Type{IH1JH2{S, Nij, A}} ) where {S, Nij, A} = eltype (A)
1566
- float_type (:: Type{IV1JH2{S, n1, Ni, A}} ) where {S, n1, Ni, A} = eltype (A)
1567
-
1568
1537
end # module
0 commit comments