From 7b7bea18f5b6dd09ef82ce7f1dc5734c308abf85 Mon Sep 17 00:00:00 2001 From: Paul Shen Date: Sat, 30 Dec 2023 15:40:56 -0500 Subject: [PATCH 1/2] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02110e5..34bac49 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ Working draft of a differentiable FDTD engine for inverse design in photonics, acoustics & RF. -Documentation at https://github.io/paulxshen/differentiable-fdtd-beta-prerelease + +Documentation at https://github.io/differentiable-fdtd-beta-prerelease + Discussion & updates at https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/12 ![a](bend-pre.gif) ![b](bend-post.gif) From 078fd9ddc1e423308cac1f2b74601ff901eae874 Mon Sep 17 00:00:00 2001 From: Paul Shen Date: Thu, 11 Jan 2024 14:59:08 -0500 Subject: [PATCH 2/2] h --- src/lazycat.jl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/lazycat.jl diff --git a/src/lazycat.jl b/src/lazycat.jl new file mode 100644 index 0000000..b2439f5 --- /dev/null +++ b/src/lazycat.jl @@ -0,0 +1,46 @@ +struct Cat{T,N}<:AbstractArray{T,N} + v + dims +ends +sz +len +function Cat(a...;dims) +ends=cumsum(size.(a,dims)) +sz=size(a[1]) +sz=(sz[1:dims-1],ends[end],sz[dims+1:end]) +len=sum(length.(a)) + new{eltype(a[1]),ndims(a[1])}(a,dims,ends,sz,len) +end +end +lcat(a...;dims)=Cat(a...;dims) +lvcat(a...)=lcat(a...;dims=1) +lhcat(a...)=lcat(a...;dims=2) +Base.size(m::Cat)=m.sz +Base.length(m::Cat)=m.len +Base.collect(m::Cat)=cat(m.v...;dims=m.dims) +Base.vec(m::Cat)=vcat(vec.(m.v)...;) +function overlap(ends,i::Int) + vi=ss(ends,i) + if vi>1 + return [vi],[i-ends[vi-1]] + end + [vi],[i] + end +function overlap(ends,r::) + (vi1,),(i1,)=overlap(ends,r[1]) + (vi2,),(i2,)=overlap(ends,r[end]) + vi1:vi2,[if vi==vi1 + i1:ends[vi1] +elseif vi==vi2 + 1:i2 +else + (:) +end for vi=vi1:vi2] + end +function Base.getindex(m::Cat,I...) +@unpack v,dims,ends=m +vi,vr=overlap(ends,I[dims]) +I1=I[1:dims-1] +I2=I[dims+1:end] +cat([v[i][I1...,r,I2...] for (i,r)=zip(vi,vr)]...;dims) +end \ No newline at end of file