11using Base: DimOrInd, Dims, OneTo
2- using TypeParameterAccessors: IsWrappedArray, unwrap_array_type, set_eltype, similartype
2+ using . Vendored . TypeParameterAccessors: IsWrappedArray, unwrap_array_type, set_eltype, similartype
33
44# # Custom `NDTensors.similar` implementation.
55# # More extensive than `Base.similar`.
66
77# This function actually allocates the data.
88# NDTensors.similar
99function similar (arraytype:: Type{<:AbstractArray} , dims:: Tuple )
10- shape = NDTensors. to_shape (arraytype, dims)
11- return similartype (arraytype, shape)(undef, NDTensors. to_shape (arraytype, shape))
10+ shape = NDTensors. to_shape (arraytype, dims)
11+ return similartype (arraytype, shape)(undef, NDTensors. to_shape (arraytype, shape))
1212end
1313
1414# This function actually allocates the data.
1515# Catches conversions of dimensions specified by ranges
1616# dimensions specified by integers with `Base.to_shape`.
1717# NDTensors.similar
1818function similar (arraytype:: Type{<:AbstractArray} , dims:: Dims )
19- return similartype (arraytype, dims)(undef, dims)
19+ return similartype (arraytype, dims)(undef, dims)
2020end
2121
2222# NDTensors.similar
2323function similar (arraytype:: Type{<:AbstractArray} , dims:: DimOrInd... )
24- return similar (arraytype, NDTensors. to_shape (dims))
24+ return similar (arraytype, NDTensors. to_shape (dims))
2525end
2626
2727# Handles range inputs, `Base.to_shape` converts them to integer dimensions.
2828# See Julia's `base/abstractarray.jl`.
2929# NDTensors.similar
3030function similar (
31- arraytype:: Type{<:AbstractArray} ,
32- shape:: Tuple{Union{Integer,OneTo},Vararg{Union{Integer,OneTo}}} ,
33- )
34- return NDTensors. similar (arraytype, NDTensors. to_shape (shape))
31+ arraytype:: Type{<:AbstractArray} ,
32+ shape:: Tuple{Union{Integer, OneTo}, Vararg{Union{Integer, OneTo}}} ,
33+ )
34+ return NDTensors. similar (arraytype, NDTensors. to_shape (shape))
3535end
3636
3737# NDTensors.similar
3838function similar (arraytype:: Type{<:AbstractArray} , eltype:: Type , dims:: Tuple )
39- return NDTensors. similar (similartype (arraytype, eltype, dims), dims)
39+ return NDTensors. similar (similartype (arraytype, eltype, dims), dims)
4040end
4141
4242# TODO : Add an input `structure` which can store things like the nonzero
7070# TODO : Maybe makes an empty array, i.e. `similartype(arraytype, eltype)()`?
7171# NDTensors.similar
7272function similar (arraytype:: Type{<:AbstractArray} , eltype:: Type )
73- return error (" Must specify dimensions." )
73+ return error (" Must specify dimensions." )
7474end
7575
7676# # NDTensors.similar for instances
7777
7878# NDTensors.similar
7979function similar (array:: AbstractArray , eltype:: Type , dims:: Tuple )
80- return NDTensors. similar (similartype (typeof (array), eltype), dims)
80+ return NDTensors. similar (similartype (typeof (array), eltype), dims)
8181end
8282
8383# NDTensors.similar
8484function similar (array:: AbstractArray , eltype:: Type , dims:: Int )
85- return NDTensors. similar (similartype (typeof (array), eltype), dims)
85+ return NDTensors. similar (similartype (typeof (array), eltype), dims)
8686end
8787
8888# NDTensors.similar
@@ -91,7 +91,7 @@ similar(array::AbstractArray, dims::Tuple) = NDTensors.similar(typeof(array), di
9191# Use the `size` to determine the dimensions
9292# NDTensors.similar
9393function similar (array:: AbstractArray , eltype:: Type )
94- return NDTensors. similar (typeof (array), eltype, size (array))
94+ return NDTensors. similar (typeof (array), eltype, size (array))
9595end
9696
9797# Use the `size` to determine the dimensions
0 commit comments