Skip to content

Commit 54ab121

Browse files
committed
Get NDTensors working again
1 parent cb85064 commit 54ab121

File tree

93 files changed

+87
-2010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+87
-2010
lines changed

NDTensors/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
2929
StridedViews = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143"
3030
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
3131
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
32+
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"
3233
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
3334

3435
[weakdeps]
@@ -55,6 +56,9 @@ NDTensorsOctavianExt = "Octavian"
5556
NDTensorsTBLISExt = "TBLIS"
5657
NDTensorscuTENSORExt = "cuTENSOR"
5758

59+
[sources]
60+
TypeParameterAccessors = {url = "https://github.com/ITensor/TypeParameterAccessors.jl"}
61+
5862
[compat]
5963
AMDGPU = "0.9, 1"
6064
Accessors = "0.1.33"

NDTensors/ext/NDTensorsGPUArraysCoreExt/blocksparsetensor.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GPUArraysCore: @allowscalar, AbstractGPUArray
2-
using NDTensors: NDTensors, BlockSparseTensor, dense, diag, map_diag!
3-
using NDTensors.DiagonalArrays: diaglength
2+
using NDTensors: NDTensors, BlockSparseTensor, dense, diag, diaglength, map_diag!
43
using NDTensors.Expose: Exposed, unexpose
54

65
## TODO to circumvent issues with blocksparse and scalar indexing
@@ -11,7 +10,7 @@ function NDTensors.diag(ETensor::Exposed{<:AbstractGPUArray,<:BlockSparseTensor}
1110
return diag(dense(unexpose(ETensor)))
1211
end
1312

14-
## TODO scalar indexing is slow here
13+
## TODO scalar indexing is slow here
1514
function NDTensors.map_diag!(
1615
f::Function,
1716
exposed_t_destination::Exposed{<:AbstractGPUArray,<:BlockSparseTensor},

NDTensors/src/NDTensors.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include("abstractarray/similar.jl")
1717
include("abstractarray/mul.jl")
1818
include("abstractarray/permutedims.jl")
1919
include("abstractarray/generic_array_constructors.jl")
20+
include("abstractarray/diaginterface.jl")
2021
include("array/permutedims.jl")
2122
include("array/mul.jl")
2223
include("tupletools.jl")
@@ -91,15 +92,6 @@ include("empty/adapt.jl")
9192
#
9293
include("deprecated.jl")
9394

94-
#####################################
95-
# NDTensorsNamedDimsArraysExt
96-
# I tried putting this inside of an
97-
# `NDTensorsNamedDimsArraysExt` module
98-
# but for some reason it kept overloading
99-
# `Base.similar` instead of `NDTensors.similar`.
100-
#
101-
include("NDTensorsNamedDimsArraysExt/NDTensorsNamedDimsArraysExt.jl")
102-
10395
#####################################
10496
# A global timer used with TimerOutputs.jl
10597
#

NDTensors/src/NDTensorsNamedDimsArraysExt/NDTensorsNamedDimsArraysExt.jl

Lines changed: 0 additions & 6 deletions
This file was deleted.

NDTensors/src/NDTensorsNamedDimsArraysExt/fill.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

NDTensors/src/NDTensorsNamedDimsArraysExt/similar.jl

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Selected interface functions from https://github.com/ITensor/DiagonalArrays.jl,
2+
# copied here so we don't have to depend on `DiagonalArrays.jl`.
3+
4+
function diaglength(a::AbstractArray)
5+
return minimum(size(a))
6+
end
7+
8+
function diagstride(a::AbstractArray)
9+
s = 1
10+
p = 1
11+
for i in 1:(ndims(a) - 1)
12+
p *= size(a, i)
13+
s += p
14+
end
15+
return s
16+
end
17+
18+
function diagindices(a::AbstractArray)
19+
maxdiag = LinearIndices(a)[CartesianIndex(ntuple(Returns(diaglength(a)), ndims(a)))]
20+
return 1:diagstride(a):maxdiag
21+
end
22+
23+
function diagindices(a::AbstractArray{<:Any,0})
24+
return Base.OneTo(1)
25+
end
26+
27+
function diagview(a::AbstractArray)
28+
return @view a[diagindices(a)]
29+
end

NDTensors/src/abstractarray/generic_array_constructors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using .TypeParameterAccessors:
1+
using TypeParameterAccessors:
22
unwrap_array_type, specify_default_type_parameters, type_parameter
33

44
# Convert to Array, avoiding copying if possible

NDTensors/src/abstractarray/iscu.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using .TypeParameterAccessors: unwrap_array_type
1+
using TypeParameterAccessors: unwrap_array_type
22
# TODO: Make `isgpu`, `ismtl`, etc.
33
# For `isgpu`, will require a `NDTensorsGPUArrayCoreExt`.
44
iscu(A::AbstractArray) = iscu(typeof(A))

NDTensors/src/abstractarray/set_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using .TypeParameterAccessors: TypeParameterAccessors
1+
using TypeParameterAccessors: TypeParameterAccessors
22

33
"""
44
# Do we still want to define things like this?

0 commit comments

Comments
 (0)