Skip to content

Commit d1dd84c

Browse files
authored
Merge branch 'main' into ITensors_qnindex_docs
2 parents 73d196b + 3fa632c commit d1dd84c

File tree

18 files changed

+93
-61
lines changed

18 files changed

+93
-61
lines changed

NDTensors/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NDTensors"
22
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
33
authors = ["Matthew Fishman <[email protected]>"]
4-
version = "0.4.0"
4+
version = "0.4.4"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -90,7 +90,7 @@ StridedViews = "0.2.2, 0.3"
9090
TBLIS = "0.2"
9191
TimerOutputs = "0.5.5"
9292
TupleTools = "1.2.0"
93-
TypeParameterAccessors = "0.2"
93+
TypeParameterAccessors = "0.3"
9494
VectorInterface = "0.4.2, 0.5"
9595
cuTENSOR = "2"
9696
julia = "1.10"
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
# TypeParameterAccessors definitions
2-
using NDTensors.TypeParameterAccessors:
3-
TypeParameterAccessors, Position, default_type_parameters
1+
using AMDGPU: ROCArray
42
using NDTensors.GPUArraysCoreExtensions: storagemode
5-
using AMDGPU: AMDGPU, ROCArray
6-
7-
function TypeParameterAccessors.default_type_parameters(::Type{<:ROCArray})
8-
return (default_type_parameters(AbstractArray)..., AMDGPU.Mem.HIPBuffer)
9-
end
3+
using NDTensors.TypeParameterAccessors: TypeParameterAccessors, Position
104

115
TypeParameterAccessors.position(::Type{<:ROCArray}, ::typeof(storagemode)) = Position(3)
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
# TypeParameterAccessors definitions
2-
using CUDA: CUDA, CuArray
3-
using NDTensors.TypeParameterAccessors:
4-
TypeParameterAccessors, Position, default_type_parameters
1+
using CUDA: CuArray
52
using NDTensors.GPUArraysCoreExtensions: storagemode
3+
using NDTensors.TypeParameterAccessors: TypeParameterAccessors, Position
64

75
function TypeParameterAccessors.position(::Type{<:CuArray}, ::typeof(storagemode))
86
return Position(3)
97
end
10-
11-
function TypeParameterAccessors.default_type_parameters(::Type{<:CuArray})
12-
return (default_type_parameters(AbstractArray)..., CUDA.Mem.DeviceBuffer)
13-
end
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
using Metal: Metal, MtlArray
2-
# `TypeParameterAccessors.jl` definitions.
3-
4-
using NDTensors.TypeParameterAccessors: TypeParameterAccessors, Position
1+
using Metal: MtlArray
52
using NDTensors.GPUArraysCoreExtensions: storagemode
3+
using NDTensors.TypeParameterAccessors: TypeParameterAccessors, Position
64

75
function TypeParameterAccessors.position(::Type{<:MtlArray}, ::typeof(storagemode))
86
return Position(3)
97
end
10-
11-
function TypeParameterAccessors.default_type_parameters(::Type{<:MtlArray})
12-
return (Float32, 1, Metal.DefaultStorageMode)
13-
end

NDTensors/src/blocksparse/block.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ sethash!(b::Block, h::UInt) = (b.hash[] = h; return b)
7575
#
7676

7777
length(::Block{N}) where {N} = N
78+
length(::Type{<:Block{N}}) where {N} = N
7879

7980
isless(b1::Block, b2::Block) = isless(Tuple(b1), Tuple(b2))
8081

NDTensors/src/blocksparse/blockoffsets.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ const BlockOffsets{N} = Dictionary{Block{N},Int}
1212

1313
BlockOffset(block::Block{N}, offset::Int) where {N} = BlockOffset{N}(block, offset)
1414

15-
Base.ndims(::Blocks{N}) where {N} = N
16-
Base.ndims(::BlockOffset{N}) where {N} = N
17-
Base.ndims(::BlockOffsets{N}) where {N} = N
18-
1915
blocktype(bofs::BlockOffsets) = keytype(bofs)
2016

2117
nzblock(bof::BlockOffset) = first(bof)

NDTensors/src/blocksparse/contract_generic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function contract_blockoffsets(
1111
indsR,
1212
labelsR,
1313
)
14-
N1 = ndims(boffs1)
15-
N2 = ndims(boffs2)
14+
N1 = length(blocktype(boffs1))
15+
N2 = length(blocktype(boffs2))
1616
NR = length(labelsR)
1717
ValNR = ValLength(labelsR)
1818
labels1_to_labels2, labels1_to_labelsR, labels2_to_labelsR = contract_labels(

NDTensors/src/blocksparse/contract_sequential.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function contract_blockoffsets(
99
indsR,
1010
labelsR,
1111
)
12-
N1 = ndims(boffs1)
13-
N2 = ndims(boffs2)
12+
N1 = length(blocktype(boffs1))
13+
N2 = length(blocktype(boffs2))
1414
NR = length(labelsR)
1515
ValNR = ValLength(labelsR)
1616
labels1_to_labels2, labels1_to_labelsR, labels2_to_labelsR = contract_labels(

NDTensors/src/blocksparse/diagblocksparse.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using LinearAlgebra: LinearAlgebra
12
using TypeParameterAccessors: similartype
23

34
export DiagBlockSparse, DiagBlockSparseTensor
@@ -448,22 +449,16 @@ function dense(
448449
end
449450

450451
# convert to Dense
451-
function dense(T::TensorT) where {TensorT<:DiagBlockSparseTensor}
452-
R = zeros(dense(TensorT), inds(T))
453-
for i in 1:diaglength(T)
454-
setdiagindex!(R, getdiagindex(T, i), i)
455-
end
456-
return R
452+
function dense(T::DiagBlockSparseTensor)
453+
return dense(denseblocks(T))
457454
end
458455

459456
# convert to BlockSparse
460457
function denseblocks(D::Tensor)
461458
nzblocksD = nzblocks(D)
462-
T = BlockSparseTensor(eltype(D), nzblocksD, inds(D))
459+
T = BlockSparseTensor(datatype(D), nzblocksD, inds(D))
463460
for b in nzblocksD
464-
for n in 1:diaglength(D)
465-
setdiagindex!(T, getdiagindex(D, n), n)
466-
end
461+
T[b] = D[b]
467462
end
468463
return T
469464
end
@@ -588,8 +583,13 @@ function _contract!!(
588583
return R
589584
end
590585

591-
# TODO: Improve this with FillArrays.jl
592-
norm(S::UniformDiagBlockSparseTensor) = sqrt(mindim(S) * abs2(data(S)))
586+
function LinearAlgebra.norm(D::UniformDiagBlockSparseTensor)
587+
normD² = zero(eltype(D))
588+
for b in nzblocks(D)
589+
normD² += norm(D[b])^2
590+
end
591+
return (abs(normD²))
592+
end
593593

594594
function contraction_output(
595595
T1::TensorT1, labelsT1, T2::TensorT2, labelsT2, labelsR

NDTensors/src/dense/dense.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ function copy(D::Dense)
105105
return Dense(copy(expose(data(D))))
106106
end
107107

108+
function Base.copyto!(R::Dense, T::Dense)
109+
copyto!(expose(data(R)), expose(data(T)))
110+
return R
111+
end
112+
108113
function Base.real(T::Type{<:Dense})
109114
return set_datatype(T, similartype(datatype(T), real(eltype(T))))
110115
end

0 commit comments

Comments
 (0)