From 98f45726364263224cd254aa7f378f894d577e9a Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Tue, 9 Sep 2025 14:23:47 -0400 Subject: [PATCH 1/7] Fix sqrt decomp --- src/tensor_operations/matrix_decomposition.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tensor_operations/matrix_decomposition.jl b/src/tensor_operations/matrix_decomposition.jl index 8983997d1a..cfbb0acf65 100644 --- a/src/tensor_operations/matrix_decomposition.jl +++ b/src/tensor_operations/matrix_decomposition.jl @@ -581,8 +581,8 @@ using NDTensors: map_diag! function sqrt_decomp(D::ITensor, u::Index, v::Index) (storage(D) isa Union{Diag,DiagBlockSparse}) || error("Must be a diagonal matrix ITensor.") - sqrtDL = diag_itensor(u, dag(u)') - sqrtDR = diag_itensor(v, dag(v)') + sqrtDL = adapt(datatype(D))(diag_itensor(u, dag(u)')) + sqrtDR = adapt(datatype(D))(diag_itensor(v, dag(v)')) map_diag!(sqrt ∘ abs, sqrtDL, D) map_diag!(sqrt ∘ abs, sqrtDR, D) δᵤᵥ = copy(D) From 3e2c454faad356627e0f74635c3465a60210924d Mon Sep 17 00:00:00 2001 From: Joseph Tindall <51231103+JoeyT1994@users.noreply.github.com> Date: Tue, 9 Sep 2025 14:50:35 -0400 Subject: [PATCH 2/7] Update src/tensor_operations/matrix_decomposition.jl Co-authored-by: Matt Fishman --- src/tensor_operations/matrix_decomposition.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tensor_operations/matrix_decomposition.jl b/src/tensor_operations/matrix_decomposition.jl index cfbb0acf65..4e2acecb86 100644 --- a/src/tensor_operations/matrix_decomposition.jl +++ b/src/tensor_operations/matrix_decomposition.jl @@ -581,8 +581,8 @@ using NDTensors: map_diag! function sqrt_decomp(D::ITensor, u::Index, v::Index) (storage(D) isa Union{Diag,DiagBlockSparse}) || error("Must be a diagonal matrix ITensor.") - sqrtDL = adapt(datatype(D))(diag_itensor(u, dag(u)')) - sqrtDR = adapt(datatype(D))(diag_itensor(v, dag(v)')) + sqrtDL = adapt(datatype(D), diag_itensor(u, dag(u)')) + sqrtDR = adapt(datatype(D), diag_itensor(v, dag(v)')) map_diag!(sqrt ∘ abs, sqrtDL, D) map_diag!(sqrt ∘ abs, sqrtDR, D) δᵤᵥ = copy(D) From 16ec2c7d47a92fefd0be1b542538bf2bf2d12297 Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Tue, 9 Sep 2025 16:41:46 -0400 Subject: [PATCH 3/7] Test and version update --- Project.toml | 2 +- test/base/test_svd.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6788ce4506..5a790df5bb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensors" uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.9.9" +version = "0.9.10" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/test/base/test_svd.jl b/test/base/test_svd.jl index 994fd684c4..d76484b802 100644 --- a/test/base/test_svd.jl +++ b/test/base/test_svd.jl @@ -206,6 +206,8 @@ include(joinpath(@__DIR__, "utils", "util.jl")) for dir in [ITensors.Out, ITensors.In] L, R, spec = ITensors.factorize_svd(A, l1, l2; dir, ortho="none") + @test datatype(L) == datatype(A) + @test datatype(R) == datatype(A) @test dir == ITensors.dir(commonind(L, R)) @test norm(L * R - A) <= 1e-14 end From 8c4ea7814a6e7abf970b680a68c5227e012c6265 Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Thu, 11 Sep 2025 10:47:08 -0400 Subject: [PATCH 4/7] Run over array types --- test/base/test_svd.jl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/base/test_svd.jl b/test/base/test_svd.jl index d76484b802..454cb5f328 100644 --- a/test/base/test_svd.jl +++ b/test/base/test_svd.jl @@ -1,4 +1,6 @@ -using ITensors +using Adapt: adapt +using ITensors: datatype +using JLArrays: JLArray using Test using Suppressor @@ -205,11 +207,14 @@ include(joinpath(@__DIR__, "utils", "util.jl")) end for dir in [ITensors.Out, ITensors.In] - L, R, spec = ITensors.factorize_svd(A, l1, l2; dir, ortho="none") - @test datatype(L) == datatype(A) - @test datatype(R) == datatype(A) - @test dir == ITensors.dir(commonind(L, R)) - @test norm(L * R - A) <= 1e-14 + for arrayt in (Array, JLArray) + A′ = adapt(arrayt, A) + L, R, spec = ITensors.factorize_svd(A, l1, l2; dir, ortho="none") + @test datatype(L) == datatype(A) + @test datatype(R) == datatype(A) + @test dir == ITensors.dir(commonind(L, R)) + @test norm(L * R - A) <= 1e-14 + end end end From 9b71bd47f03e0723a6b6e40cb97fff77b56f49ca Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Thu, 11 Sep 2025 11:16:40 -0400 Subject: [PATCH 5/7] Add adapt to base tests toml --- test/base/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/base/Project.toml b/test/base/Project.toml index 40db993045..ae14ef7712 100644 --- a/test/base/Project.toml +++ b/test/base/Project.toml @@ -1,4 +1,5 @@ [deps] +Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" From ea07aba94e3fe62d03fff18fad80f286f2090e42 Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Thu, 11 Sep 2025 12:27:59 -0400 Subject: [PATCH 6/7] Update test project toml too --- test/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Project.toml b/test/Project.toml index d9a07bd2bc..d75b901258 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] +Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a" From 53ae382b2bffb4838e90bf7c7e45af71a2dbd574 Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Thu, 11 Sep 2025 12:52:11 -0400 Subject: [PATCH 7/7] Also JL Arrays --- test/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Project.toml b/test/Project.toml index d75b901258..6b4fae9f43 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -8,6 +8,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" +JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"