Skip to content

Use Int constructor to access block field #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2023
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
4 changes: 2 additions & 2 deletions src/Fun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function coefficient(f::Fun,kr::AbstractRange)
f.coefficients[first(kr):min(b, end)]
end

coefficient(f::Fun,K::Block) = coefficient(f,blockrange(space(f),K.n[1]))
coefficient(f::Fun,K::Block) = coefficient(f,blockrange(space(f),Int(K)))
coefficient(f::Fun,::Colon) = coefficient(f,1:dimension(space(f)))

# convert to vector while computing coefficients
Expand Down Expand Up @@ -461,7 +461,7 @@ julia> ncoefficients(f)
"""
ncoefficients(f::Fun)::Int = length(f.coefficients)

blocksize(f::Fun) = (block(space(f),ncoefficients(f)).n[1],)
blocksize(f::Fun) = (Int(block(space(f),ncoefficients(f))),)

"""
stride(f::Fun)
Expand Down
16 changes: 8 additions & 8 deletions src/Multivariate/TensorSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ block(sp::Tensorizer,k::Int) = Block(findfirst(x->x≥k, _cumsum(blocklengths(sp
block(sp::CachedIterator,k::Int) = block(sp.iterator,k)

blocklength(it,k) = blocklengths(it)[k]
blocklength(it,k::Block) = blocklength(it,k.n[1])
blocklength(it,k::Block) = blocklength(it,Int(k))
blocklength(it,k::BlockRange) = blocklength(it,Int.(k))

blocklengths(::TrivialTensorizer{2}) = 1:∞
Expand All @@ -237,8 +237,8 @@ _K_sum(bl::AbstractVector, K) = sum(bl[1:K])
_K_sum(bl::Integer, K) = bl
blockstop(it, K)::Int = _K_sum(blocklengths(it), K)

blockstart(it,K::Block) = blockstart(it,K.n[1])
blockstop(it,K::Block) = blockstop(it,K.n[1])
blockstart(it,K::Block) = blockstart(it,Int(K))
blockstop(it,K::Block) = blockstop(it,Int(K))


blockrange(it,K) = blockstart(it,K):blockstop(it,K)
Expand All @@ -249,10 +249,10 @@ blockrange(it,K::BlockRange) = blockstart(it,first(K)):blockstop(it,last(K))

# convert from block, subblock to tensor
subblock2tensor(rt::TrivialTensorizer{2},K,k) =
(k,K.n[1]-k+1)
(k,Int(K)-k+1)

subblock2tensor(rt::CachedIterator{II,TrivialTensorizer{2}},K,k) where {II} =
(k,K.n[1]-k+1)
(k,Int(K)-k+1)


subblock2tensor(rt::CachedIterator,K,k) = rt[blockstart(rt,K)+k-1]
Expand Down Expand Up @@ -602,10 +602,10 @@ function totensor(it::Tensorizer,M::AbstractVector)
n=length(M)
B=block(it,n)

#ret=zeros(eltype(M),[sum(it.blocks[i][1:min(B.n[1],length(it.blocks[i]))]) for i=1:length(it.blocks)]...)
#ret=zeros(eltype(M),[sum(it.blocks[i][1:min(Int(B),length(it.blocks[i]))]) for i=1:length(it.blocks)]...)

ret=zeros(eltype(M),sum(it.blocks[1][1:min(B.n[1],length(it.blocks[1]))]),
sum(it.blocks[2][1:min(B.n[1],length(it.blocks[2]))]))
ret=zeros(eltype(M),sum(it.blocks[1][1:min(Int(B),length(it.blocks[1]))]),
sum(it.blocks[2][1:min(Int(B),length(it.blocks[2]))]))

k=1
for index in it
Expand Down
2 changes: 1 addition & 1 deletion src/Multivariate/TrivialTensorFun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

# TensorSpace evaluation
function evaluate(f::TrivialTensorFun{d, SS, T},x...) where {d, SS, T}
highest_order = f.orders.n[1]
highest_order = Int(f.orders)
n = length(f.coefficients)

# this could be lazy evaluated for the sparse case
Expand Down
10 changes: 5 additions & 5 deletions src/Operators/SubOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function checkbounds(::Type{Bool}, A::Operator,kr,jr)
end

checkbounds(::Type{Bool}, A::Operator,K::Block,J::Block) =
1 ≤ first(K.n[1]) ≤ length(blocklengths(rangespace(A))) &&
1 ≤ first(J.n[1]) ≤ length(blocklengths(domainspace(A)))
1 ≤ first(Int(K)) ≤ length(blocklengths(rangespace(A))) &&
1 ≤ first(Int(J)) ≤ length(blocklengths(domainspace(A)))

checkbounds(::Type{Bool}, A::Operator,K::BlockRange{1},J::BlockRange{1}) =
isempty(K) || isempty(J) ||
Expand Down Expand Up @@ -58,8 +58,8 @@ function SubOperator(A,inds::NTuple{2,Block},lu)
_SubOperator(A, inds, lu, domainspace(A), rangespace(A))
end
function _SubOperator(A, inds, lu, dsp, rsp)
SubOperator(A,inds,(blocklengths(rsp)[inds[1].n[1]],
blocklengths(dsp)[inds[2].n[1]]),lu)
SubOperator(A,inds,(blocklengths(rsp)[Int(inds[1])],
blocklengths(dsp)[Int(inds[2])]),lu)
end

SubOperator(A, inds::NTuple{2,Block}) = SubOperator(A,inds,subblockbandwidths(A))
Expand Down Expand Up @@ -232,7 +232,7 @@ blockbandwidths(S::SubOperator{<:Any,<:Any,NTuple{2,AbstractRange{Int}}}) =
function blockbandwidths(S::SubOperator{<:Any,<:Any,NTuple{2,BlockRange1}})
KR,JR = parentindices(S)
l,u = blockbandwidths(parent(S))
sh = first(KR).n[1]-first(JR).n[1]
sh = Int(first(KR)) - Int(first(JR))
l-sh,u+sh
end

Expand Down
6 changes: 5 additions & 1 deletion src/Operators/general/FiniteOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ end


bandwidths(T::FiniteOperator) = bandwidths(T.matrix)
blockbandwidths(T::FiniteOperator) = block(rangespace(T),size(T.matrix,1)).n[1]-1,block(domainspace(T),size(T.matrix,2)).n[1]-1
function blockbandwidths(T::FiniteOperator)
n1 = Int(block(rangespace(T),size(T.matrix,1)))-1
n2 = Int(block(domainspace(T),size(T.matrix,2)))-1
return n1, n2
end
Base.maximum(K::FiniteOperator) = maximum(K.matrix)
2 changes: 1 addition & 1 deletion src/Operators/general/InterlaceOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ function blockbanded_interlace_convert!(S,ret)
k = 0
m = 0
for κ=1:size(M,1)
if K.n[1] ≤ blocksize(M[κ,ξ],1) && J.n[1] ≤ blocksize(M[κ,ξ],2)
if Int(K) ≤ blocksize(M[κ,ξ],1) && Int(J) ≤ blocksize(M[κ,ξ],2)
MKJ = M[κ,ξ][K,J]::Matrix{T}
n,m = size(MKJ)
Bs[k+1:k+n,j+1:j+m] = MKJ
Expand Down
14 changes: 7 additions & 7 deletions src/Spaces/SubSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ function blocklengths(sp::SubSpace{DS,UnitRange{Int}}) where DS
B1 = block(sp.space,N)
B2 = block(sp.space,M)
# if the blocks are equal, we have only one bvlock
B1 == B2 && return [Zeros{Int}(B1.n[1]-1); length(sp.indexes)]
B1 == B2 && return [Zeros{Int}(Int(B1)-1); length(sp.indexes)]

[Zeros{Int}(B1.n[1]-1);
[Zeros{Int}(Int(B1)-1);
blockstop(sp.space,B1)-N+1;
blocklengths(sp.space)[B1.n[1]+1:B2.n[1]-1];
blocklengths(sp.space)[Int(B1)+1:Int(B2)-1];
M-blockstart(sp.space,B2)+1]
end

function blocklengths(sp::SubSpace{DS,<:AbstractInfUnitRange{Int}}) where DS
N = first(sp.indexes)
B1 = block(sp.space,N)

Vcat([Zeros{Int}(B1.n[1]-1); blockstop(sp.space,B1)-N+1],
blocklengths(sp.space)[B1.n[1]+1:∞])
Vcat([Zeros{Int}(Int(B1)-1); blockstop(sp.space,B1)-N+1],
blocklengths(sp.space)[Int(B1)+1:∞])
end

blocklengths(sp::SubSpace{DS,Block{1,T}}) where {DS, T} =
Expand All @@ -64,8 +64,8 @@ reindex(sp::SubSpace, br::Tuple{AbstractVector{Int}}, ks::Tuple{BlockRange1}) =


## Block
blocklengths(sp::SubSpace{DS,Block}) where {DS} = [blocklengths(sp.space)[sp.indexes.n[1]]]
dimension(sp::SubSpace{DS,Block}) where {DS} = blocklengths(sp.space)[sp.indexes.n[1]]
blocklengths(sp::SubSpace{DS,Block}) where {DS} = [blocklengths(sp.space)[Int(sp.indexes)]]
dimension(sp::SubSpace{DS,Block}) where {DS} = blocklengths(sp.space)[Int(sp.indexes)]


blocklengths(sp::SubSpace{DS,BlockRange1}) where {DS} = blocklengths(sp.space)[Int.(sp.indexes)]
Expand Down
2 changes: 1 addition & 1 deletion src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function _default_Fun(f, d::Space)
end

b = block(d,length(cf.coefficients))
bs = blockstart(d,max(b.n[1]-2,1))
bs = blockstart(d,max(Int(b)-2,1))

# we allow for transformed coefficients being a different size
##TODO: how to do scaling for unnormalized bases like Jacobi?
Expand Down