Skip to content

Commit c1af7db

Browse files
authored
Change Adjoints to be ComponentArray
This PR aims to avoid issues like: ``` using ComponentArrays A = ComponentMatrix(ones(2, 2), Axis(:a, :b), FlatAxis()) A[:b, :] # works A'[:, :b] # fails! ``` by wrapping adjoint operations in the underlying data of the ComponentArray structure. By not having to care about adjoints of ComponentArray, we arguably also reduce overall cognitive load.
1 parent cbb24ef commit c1af7db

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/linear_algebra.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,18 @@ for op in [:*, :\, :/]
4242
end
4343
end
4444
end
45-
end
45+
end
46+
47+
48+
for op in [:adjoint, :transpose]
49+
@eval begin
50+
function LinearAlgebra.$op(M::ComponentMatrix{T,A,Tuple{Ax1,Ax2}}) where {T,A,Ax1,Ax2}
51+
data = $op(getdata(M))
52+
return ComponentArray(data, (Ax2(), Ax1())[1:ndims(data)]...)
53+
end
54+
55+
function LinearAlgebra.$op(M::ComponentVector{T,A,Tuple{Ax1}}) where {T,A,Ax1}
56+
return ComponentMatrix($op(getdata(M)), FlatAxis(), Ax1())
57+
end
58+
end
59+
end

0 commit comments

Comments
 (0)