Skip to content

Commit 831c906

Browse files
committed
define tuplemortar
1 parent df2aad7 commit 831c906

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/blockedtuple.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ struct BlockedTuple{BlockLengths,Flat} <: AbstractBlockTuple
7979
end
8080

8181
# TensorAlgebra Interface
82-
BlockedTuple(tt::Vararg{Tuple}) = BlockedTuple{length.(tt)}(flatten_tuples(tt))
82+
tuplemortar(tt::Vararg{Tuple}) = BlockedTuple{length.(tt)}(flatten_tuples(tt))
83+
function BlockedTuple(flat::Tuple, BlockLengths::Tuple{Vararg{Int}})
84+
return BlockedTuple{BlockLengths}(flat)
85+
end
8386
BlockedTuple(bt::AbstractBlockTuple) = BlockedTuple{blocklengths(bt)}(Tuple(bt))
8487

8588
# Base interface

test/test_blockedtuple.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Test: @test, @test_throws
33
using BlockArrays: Block, blocklength, blocklengths, blockedrange, blockisequal, blocks
44
using TestExtras: @constinferred
55

6-
using TensorAlgebra: BlockedTuple
6+
using TensorAlgebra: BlockedTuple, tuplemortar
77

88
@testset "BlockedTuple" begin
99
flat = (true, 'a', 2, "b", 3.0)
@@ -12,7 +12,8 @@ using TensorAlgebra: BlockedTuple
1212
bt = BlockedTuple{divs}(flat)
1313

1414
@test (@constinferred Tuple(bt)) == flat
15-
@test bt == BlockedTuple((true,), ('a', 2), ("b", 3.0))
15+
@test bt == tuplemortar((true,), ('a', 2), ("b", 3.0))
16+
@test bt == BlockedTuple(flat, divs)
1617
@test BlockedTuple(bt) == bt
1718
@test blocklength(bt) == 3
1819
@test blocklengths(bt) == (1, 2, 2)
@@ -38,17 +39,17 @@ using TensorAlgebra: BlockedTuple
3839

3940
@test_throws DimensionMismatch BlockedTuple{(1, 2, 3)}(flat)
4041

41-
bt = BlockedTuple((1,), (4, 2), (5, 3))
42+
bt = tuplemortar((1,), (4, 2), (5, 3))
4243
@test Tuple(bt) == (1, 4, 2, 5, 3)
4344
@test blocklengths(bt) == (1, 2, 2)
4445
@test deepcopy(bt) == bt
4546

4647
@test (@constinferred map(n -> n + 1, bt)) ==
4748
BlockedTuple{blocklengths(bt)}(Tuple(bt) .+ 1)
48-
@test bt .+ BlockedTuple((1,), (1, 1), (1, 1)) ==
49+
@test bt .+ tuplemortar((1,), (1, 1), (1, 1)) ==
4950
BlockedTuple{blocklengths(bt)}(Tuple(bt) .+ 1)
50-
@test_throws DimensionMismatch bt .+ BlockedTuple((1, 1), (1, 1), (1,))
51+
@test_throws DimensionMismatch bt .+ tuplemortar((1, 1), (1, 1), (1,))
5152

52-
bt = BlockedTuple((1:2, 1:2), (1:3,))
53-
@test length.(bt) == BlockedTuple((2, 2), (3,))
53+
bt = tuplemortar((1:2, 1:2), (1:3,))
54+
@test length.(bt) == tuplemortar((2, 2), (3,))
5455
end

0 commit comments

Comments
 (0)