Skip to content

Commit 9d017b6

Browse files
authored
Use Int constructor to access block field (#601)
1 parent ea0113e commit 9d017b6

File tree

8 files changed

+30
-26
lines changed

8 files changed

+30
-26
lines changed

src/Fun.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function coefficient(f::Fun,kr::AbstractRange)
153153
f.coefficients[first(kr):min(b, end)]
154154
end
155155

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

159159
# convert to vector while computing coefficients
@@ -461,7 +461,7 @@ julia> ncoefficients(f)
461461
"""
462462
ncoefficients(f::Fun)::Int = length(f.coefficients)
463463

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

466466
"""
467467
stride(f::Fun)

src/Multivariate/TensorSpace.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ block(sp::Tensorizer,k::Int) = Block(findfirst(x->x≥k, _cumsum(blocklengths(sp
213213
block(sp::CachedIterator,k::Int) = block(sp.iterator,k)
214214

215215
blocklength(it,k) = blocklengths(it)[k]
216-
blocklength(it,k::Block) = blocklength(it,k.n[1])
216+
blocklength(it,k::Block) = blocklength(it,Int(k))
217217
blocklength(it,k::BlockRange) = blocklength(it,Int.(k))
218218

219219
blocklengths(::TrivialTensorizer{2}) = 1:
@@ -237,8 +237,8 @@ _K_sum(bl::AbstractVector, K) = sum(bl[1:K])
237237
_K_sum(bl::Integer, K) = bl
238238
blockstop(it, K)::Int = _K_sum(blocklengths(it), K)
239239

240-
blockstart(it,K::Block) = blockstart(it,K.n[1])
241-
blockstop(it,K::Block) = blockstop(it,K.n[1])
240+
blockstart(it,K::Block) = blockstart(it,Int(K))
241+
blockstop(it,K::Block) = blockstop(it,Int(K))
242242

243243

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

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

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

257257

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

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

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

610610
k=1
611611
for index in it

src/Multivariate/TrivialTensorFun.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020

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

2626
# this could be lazy evaluated for the sparse case

src/Operators/SubOperator.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function checkbounds(::Type{Bool}, A::Operator,kr,jr)
2424
end
2525

2626
checkbounds(::Type{Bool}, A::Operator,K::Block,J::Block) =
27-
1 first(K.n[1]) length(blocklengths(rangespace(A))) &&
28-
1 first(J.n[1]) length(blocklengths(domainspace(A)))
27+
1 first(Int(K)) length(blocklengths(rangespace(A))) &&
28+
1 first(Int(J)) length(blocklengths(domainspace(A)))
2929

3030
checkbounds(::Type{Bool}, A::Operator,K::BlockRange{1},J::BlockRange{1}) =
3131
isempty(K) || isempty(J) ||
@@ -58,8 +58,8 @@ function SubOperator(A,inds::NTuple{2,Block},lu)
5858
_SubOperator(A, inds, lu, domainspace(A), rangespace(A))
5959
end
6060
function _SubOperator(A, inds, lu, dsp, rsp)
61-
SubOperator(A,inds,(blocklengths(rsp)[inds[1].n[1]],
62-
blocklengths(dsp)[inds[2].n[1]]),lu)
61+
SubOperator(A,inds,(blocklengths(rsp)[Int(inds[1])],
62+
blocklengths(dsp)[Int(inds[2])]),lu)
6363
end
6464

6565
SubOperator(A, inds::NTuple{2,Block}) = SubOperator(A,inds,subblockbandwidths(A))
@@ -232,7 +232,7 @@ blockbandwidths(S::SubOperator{<:Any,<:Any,NTuple{2,AbstractRange{Int}}}) =
232232
function blockbandwidths(S::SubOperator{<:Any,<:Any,NTuple{2,BlockRange1}})
233233
KR,JR = parentindices(S)
234234
l,u = blockbandwidths(parent(S))
235-
sh = first(KR).n[1]-first(JR).n[1]
235+
sh = Int(first(KR)) - Int(first(JR))
236236
l-sh,u+sh
237237
end
238238

src/Operators/general/FiniteOperator.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,9 @@ end
6161

6262

6363
bandwidths(T::FiniteOperator) = bandwidths(T.matrix)
64-
blockbandwidths(T::FiniteOperator) = block(rangespace(T),size(T.matrix,1)).n[1]-1,block(domainspace(T),size(T.matrix,2)).n[1]-1
64+
function blockbandwidths(T::FiniteOperator)
65+
n1 = Int(block(rangespace(T),size(T.matrix,1)))-1
66+
n2 = Int(block(domainspace(T),size(T.matrix,2)))-1
67+
return n1, n2
68+
end
6569
Base.maximum(K::FiniteOperator) = maximum(K.matrix)

src/Operators/general/InterlaceOperator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ function blockbanded_interlace_convert!(S,ret)
437437
k = 0
438438
m = 0
439439
for κ=1:size(M,1)
440-
if K.n[1] blocksize(M[κ,ξ],1) && J.n[1] blocksize(M[κ,ξ],2)
440+
if Int(K) blocksize(M[κ,ξ],1) && Int(J) blocksize(M[κ,ξ],2)
441441
MKJ = M[κ,ξ][K,J]::Matrix{T}
442442
n,m = size(MKJ)
443443
Bs[k+1:k+n,j+1:j+m] = MKJ

src/Spaces/SubSpace.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ function blocklengths(sp::SubSpace{DS,UnitRange{Int}}) where DS
2929
B1 = block(sp.space,N)
3030
B2 = block(sp.space,M)
3131
# if the blocks are equal, we have only one bvlock
32-
B1 == B2 && return [Zeros{Int}(B1.n[1]-1); length(sp.indexes)]
32+
B1 == B2 && return [Zeros{Int}(Int(B1)-1); length(sp.indexes)]
3333

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

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

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

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

6565

6666
## Block
67-
blocklengths(sp::SubSpace{DS,Block}) where {DS} = [blocklengths(sp.space)[sp.indexes.n[1]]]
68-
dimension(sp::SubSpace{DS,Block}) where {DS} = blocklengths(sp.space)[sp.indexes.n[1]]
67+
blocklengths(sp::SubSpace{DS,Block}) where {DS} = [blocklengths(sp.space)[Int(sp.indexes)]]
68+
dimension(sp::SubSpace{DS,Block}) where {DS} = blocklengths(sp.space)[Int(sp.indexes)]
6969

7070

7171
blocklengths(sp::SubSpace{DS,BlockRange1}) where {DS} = blocklengths(sp.space)[Int.(sp.indexes)]

src/constructors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function _default_Fun(f, d::Space)
121121
end
122122

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

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

0 commit comments

Comments
 (0)