Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuasiArrays"
uuid = "c4ea9172-b204-11e9-377d-29865faadc5c"
authors = ["Sheehan Olver <[email protected]>"]
version = "0.12.1"
version = "0.12.2"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
2 changes: 1 addition & 1 deletion src/QuasiArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import LazyArrays: MemoryLayout, UnknownLayout, Mul, ApplyLayout, BroadcastLayou
_mul, rowsupport, DiagonalLayout, adjointlayout, transposelayout, conjlayout,
sublayout, call, LazyArrayStyle, layout_getindex, _broadcast2broadcastarray, _applyarray_summary, _broadcastarray_summary,
_broadcasted_mul, simplifiable, simplify, _mul_colsupport, _mul_rowsupport,
_adjoint, _transpose
_adjoint, _transpose, _vec_mul_arguments, _transposeifnumber

import Base.IteratorsMD

Expand Down
2 changes: 1 addition & 1 deletion src/abstractquasiarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ imag(x::AbstractQuasiArray{<:Real}) = zero(x)
nd = ndims(A)
d > nd && (i == 1 || throw(BoundsError(A, (ntuple(k->Colon(),d-1)..., i))))
return view(A, idxs...)
end
end
13 changes: 8 additions & 5 deletions src/calculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ for Sum in (:sum, :cumsum)
end
end

_colon2one(::Colon) = 1
_colon2one(dims::Int) = dims

function cumsum_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiVector, dims)
a = arguments(LAY, V)
apply(*, cumsum(a[1]; dims=dims), tail(a)...)
apply(*, cumsum(a[1]; dims=_colon2one(dims)), tail(a)...)
end

function sum_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiVector, ::Colon)
function sum_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiVector, dims)
a = arguments(LAY, V)
only(*(sum(a[1]; dims=1), tail(a)...))
only(*(sum(a[1]; dims=_colon2one(dims)), tail(a)...))
end

function sum_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiMatrix, ::Colon)
function sum_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiMatrix, dims)
a = arguments(LAY, V)
only(*(sum(a[1]; dims=1), front(tail(a))..., sum(a[end]; dims=2)))
only(*(sum(a[1]; dims=_colon2one(dims)), front(tail(a))..., sum(a[end]; dims=2)))
end

sum_layout(::MemoryLayout, A, dims) = sum_size(size(A), A, dims)
Expand Down
4 changes: 4 additions & 0 deletions src/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ broadcasted(::LazyQuasiArrayStyle{N}, ::typeof(\), x::Number, A::MulQuasiArray{<
ApplyQuasiArray(*, _ldiv_scal_reduce(x, arguments(A)...)...)
broadcasted(::LazyQuasiArrayStyle{N}, ::typeof(/), A::MulQuasiArray{<:Any,N}, x::Number) where N =
ApplyQuasiArray(*, _ldiv_scal_reduce(x, arguments(A)...)...)

_transposeifnumber(a::AbstractQuasiArray{<:Number}) = transpose(a)
_vec_mul_arguments(args, (kr,jr)::Tuple{AbstractQuasiVector,Number}) = _mat_mul_arguments(args, (kr,jr))
_vec_mul_arguments(args, (kr,jr)::Tuple{Number,AbstractQuasiVector}) = _vec_mul_arguments(reverse(map(_transposeifnumber, args)), (jr,kr))
3 changes: 3 additions & 0 deletions src/quasiadjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ call(::ApplyLayout{typeof(*)}, V::QuasiTranspose) = *
arguments(LAY::ApplyLayout{typeof(*)}, V::QuasiAdjoint) = reverse(adjoint.(arguments(LAY, V')))
arguments(LAY::ApplyLayout{typeof(*)}, V::QuasiTranspose) = reverse(transpose.(arguments(LAY, V')))

call(lay::BroadcastLayout, At::QuasiTranspose) = call(lay, transpose(At))
call(lay::BroadcastLayout, At::QuasiAdjoint{<:Real}) = call(lay, At')


# This is used in ContinuumArrays.jl to ensure x' is lazy
BroadcastStyle(::Type{<:QuasiAdjoint{<:Any,<:Inclusion}}) = LazyQuasiArrayStyle{2}()
Expand Down
28 changes: 27 additions & 1 deletion src/quasireshapedarray.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
vec_layout(lay, _) = error("overload vec_layout(::$(typeof(lay)), _)")


"""
vec(a::AbstractQuasiMatrix)

reshapes a quasi-matrix into quasi-vector. The axes of the resulting
quasi-vector depends on the axes of the quasi-matrix: if the axes are
`(ax, Base.OneTo(1))` or `(Base.OneTo(1), ax)` then the unary dimension is dropped.
If the axes are both continuous then it may form a quasi-vector defined on the rectangle,
if MultivariateOrthogonalPolynomials.jl is loaded.
"""
vec(a::AbstractQuasiMatrix) = vec_layout(MemoryLayout(a), a)


reshape(parent::AbstractQuasiArray{T,N}, ndims::Val{N}) where {T,N} = parent
function reshape(parent::AbstractQuasiArray, ndims::Val{N}) where N
reshape(parent, rdims(Val(N), axes(parent)))
end
end


reshape_layout(lay, a, dims...) = error("overload reshape_layout(::$(typeof(lay)), _, dims...)")


"""
reshape(a::AbstractQuasiVector)

will reshape a quasi-vector defined on a rectangle to a quasi-matrix.
"""
reshape(a::AbstractQuasiArray, dims...) = reshape_layout(MemoryLayout(a), a, dims...)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include("test_arrayops.jl")
include("test_quasisubarray.jl")
include("test_quasipermutedims.jl")
include("test_quasireducedim.jl")
include("test_quasireshapedarray.jl")

include("test_dense.jl")
include("test_quasiadjtrans.jl")
Expand Down
16 changes: 15 additions & 1 deletion test/test_quasiadjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


using QuasiArrays, Test, Base64, LinearAlgebra
import QuasiArrays: MemoryLayout
using QuasiArrays: MemoryLayout
using LazyArrays: BroadcastLayout



@testset "QuasiAdjoint/Transpose" begin
Expand Down Expand Up @@ -258,4 +260,16 @@ import QuasiArrays: MemoryLayout
@test summary(x') == "adjoint(QuasiVector{Int64, Tuple{Vector{Float64}}})"
@test summary(transpose(x)) == "transpose(QuasiVector{Int64, Tuple{Vector{Float64}}})"
end

@testset "Broadcast AdjTrans" begin
x = QuasiArray([1,2],[0,0.5])
@test MemoryLayout(BroadcastQuasiArray(exp, x)') isa BroadcastLayout
@test MemoryLayout(transpose(BroadcastQuasiArray(exp, x))) isa BroadcastLayout
@test BroadcastQuasiArray(exp, x)'[1,0.5] == exp(2)
@test transpose(BroadcastQuasiArray(exp, x))[1,0.5] == exp(2)
@test BroadcastQuasiArray(exp, x)'[1,0.5:0.5] == [exp(2)]
@test transpose(BroadcastQuasiArray(exp, x))[1,0.5:0.5] == [exp(2)]
@test exp.(axes(x,1)') isa BroadcastQuasiArray
@test exp.(transpose(axes(x,1))) isa BroadcastQuasiArray
end
end
14 changes: 13 additions & 1 deletion test/test_quasilazy.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using QuasiArrays, LazyArrays, ArrayLayouts, Base64, Test
import QuasiArrays: QuasiLazyLayout, QuasiArrayApplyStyle, LazyQuasiMatrix, LazyQuasiArrayStyle
import LazyArrays: MulStyle, ApplyStyle
import LazyArrays: MulStyle, ApplyStyle, arguments

struct MyQuasiLazyMatrix <: LazyQuasiMatrix{Float64}
A::QuasiArray
Expand Down Expand Up @@ -86,6 +86,18 @@ Base.getindex(A::MyQuasiLazyMatrix, x::Float64, y::Float64) = A.A[x,y]
A = ApplyQuasiArray(*, ones(Inclusion([1,2,3]), Inclusion([4,5])), fill(2,Inclusion([4,5])))
@test stringmime("text/plain", A) == "(ones(Inclusion([1, 2, 3]), Inclusion([4, 5]))) * (fill(2, Inclusion([4, 5])))"
end

@testset "sub *" begin
A = QuasiArray(rand(3,3),(0:0.5:1,Base.OneTo(3)))
B = randn(3,3)
M = ApplyQuasiArray(*, A, B)
@test arguments(view(M,0.5,:)) == (B', A[0.5,:])
@test arguments(view(M,:,2)) == (A, B[:,2])

M = ApplyQuasiArray(*, B, A')
@test arguments(view(M,:,0.5)) == (B, A[0.5,:])
@test arguments(view(M,2,:)) == (A, B[2,:])
end
end
@testset "\\" begin
A = QuasiArray(rand(3,3),(0:0.5:1,0:0.5:1))
Expand Down
7 changes: 7 additions & 0 deletions test/test_quasireshapedarray.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using QuasiArrays, Test

@testset "quasireshapedarray" begin
A = QuasiArray(randn(2,3), (0:0.5:0.5, 1:0.5:2))
@test_throws ErrorException vec(A)
@test_throws ErrorException reshape(A)
end
Loading