Skip to content

Commit

Permalink
updates to FreqArray
Browse files Browse the repository at this point in the history
  • Loading branch information
1oly committed Jun 2, 2022
1 parent e834c50 commit 1728b8e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["AeroAcoustics"]
license = "MIT"
desc = "A package for post-processing of microphone array measurements"
authors = ["Oliver Lylloff <[email protected]>"]
version = "0.2.2"
version = "0.2.3"

[deps]
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
Expand Down
4 changes: 4 additions & 0 deletions src/AeroAcoustics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ using ThreadsX
import Base.length,
Base.push!,
Base.reshape
#Base.*,
#Base./,
#Base.+,
#Base.-

export Environment,
FreqArray,
Expand Down
23 changes: 22 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,33 @@ struct FreqArray{T, N, AA<:AbstractVector} <: AbstractArray{T, N}
end

# Standard array functions and indexing
FreqArray(arr::AbstractArray{T,N}, fc::AbstractVector) where {T,N} =
FreqArray{eltype(arr),N,typeof(fc)}(arr, fc)
Base.size(A::FreqArray) = size(A.arr)
Base.axes(A::FreqArray) = axes(A.arr)
Base.getindex(A::FreqArray, i::Int) = A.arr[i]
Base.getindex(A::FreqArray{T, N}, I::Vararg{Int, N}) where {T, N} = A.arr[I...]
Base.setindex!(A::FreqArray,v,i) = A.arr[i] = v
Base.getindex(A::FreqArray, ::Colon) = A.arr[:]
Base.getindex(A::FreqArray, kr::AbstractRange) = A.arr[kr]

Base.setindex!(A::FreqArray, v, i::Int) = (A.arr[i] = v)
Base.setindex!(A::FreqArray, v, I::Vararg{Int,N}) where {N} = (A.arr[I...] = v)
Base.setindex!(A::FreqArray, v, ::Colon) = (A.Arr[:] .= v)
Base.setindex!(A::FreqArray, v, kr::AbstractRange) = (A.arr[kr] .= v)

Base.similar(A::FreqArray) = FreqArray(similar(A.arr),A.fc)
Base.similar(A::FreqArray,::Type{T}) where T = FreqArray(similar(A.arr,T),A.fc)

Base.:*(x::Number, A::FreqArray) = FreqArray(x*A.arr, A.fc)
Base.:*(A::FreqArray, x::Number) = FreqArray(x*A.arr, A.fc)
Base.:/(A::FreqArray, x::Number) = FreqArray(A.arr/x, A.fc)
Base.:/(x::Number, A::FreqArray) = FreqArray(A.arr/x, A.fc)

# TODO: check that A.fc == B.fc before computing:
#Base.:*(B::FreqArray, A::FreqArray) = FreqArray(B.arr.*A.arr, A.fc)
#Base.:*(A::FreqArray, B::FreqArray) = FreqArray(A.arr.*B.arr, A.fc)
#Base.:/(A::FreqArray, B::FreqArray) = FreqArray(A.arr./B.arr, A.fc)
#Base.:/(B::FreqArray, A::FreqArray) = FreqArray(B.arr./A.arr, A.fc)
"""
Environment
Expand Down
15 changes: 15 additions & 0 deletions test/utility_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,18 @@ end
win = DSP.rect(n)
@test enbw(fs,win) == fs/n
end

@testset "FreqArray:" begin
T = ComplexF64
A = ones(ComplexF64,10,10,2)
b = ones(Int64,2)
F = FreqArray(A,b)
@test typeof(FreqArray(A,b)) === FreqArray{T,3,typeof(b)}
@test typeof(F) === typeof(F/10) === typeof(10/F)
@test typeof(F) === typeof(F*10) === typeof(10*F)
@test F.fc == (F*10).fc == (10*F).fc
@test F.fc == (F/10).fc == (10/F).fc
@test (F*10)[1] == 10.0 + 0.0im
F[1,1,1] = 2.0
@test typeof(F) == FreqArray{T,3,typeof(b)} # is it still a FreqArray?
end

0 comments on commit 1728b8e

Please sign in to comment.