Skip to content

Commit

Permalink
Part 2: rename Dense{Vector,Matrix} => {Vector,Matrix}.
Browse files Browse the repository at this point in the history
Since this seems really confusing to various people, vector and
matrix now refer to the dense array types, not the abstract tensor
type that they previously referred to. This makes it easier to
"reach" for a Vector or Matrix that are dense and harder to reach
for an AbstractVector or AbstractMatrix, which is good because it
is usually the former that you want, and not the latter.
  • Loading branch information
StefanKarpinski committed Jul 23, 2011
1 parent 38d8b8b commit 26b8497
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 48 deletions.
42 changes: 19 additions & 23 deletions j/fft.j
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@ jl_fftw_destroy_plan(precision::Union(Type{Float32}, Type{Complex64}), plan) =

# Create 1d plan

jl_fftw_plan_dft_1d(X::DenseVector{Complex128}, Y::DenseVector{Complex128}, direction::Int32) =
jl_fftw_plan_dft_1d(X::Vector{Complex128}, Y::Vector{Complex128}, direction::Int32) =
ccall(dlsym(libfftw, :fftw_plan_dft_1d),
Ptr{Void},
(Int32, Ptr{Complex128}, Ptr{Complex128}, Int32, Uint32, ),
int32(length(X)), X, Y, direction, FFTW_ESTIMATE)

jl_fftw_plan_dft_1d(X::DenseVector{Complex64}, Y::DenseVector{Complex64}, direction::Int32) =
jl_fftw_plan_dft_1d(X::Vector{Complex64}, Y::Vector{Complex64}, direction::Int32) =
ccall(dlsym(libfftwf, :fftwf_plan_dft_1d),
Ptr{Void},
(Int32, Ptr{Complex64}, Ptr{Complex64}, Int32, Uint32, ),
int32(length(X)), X, Y, direction, FFTW_ESTIMATE)

jl_fftw_plan_dft_r2c_1d(X::DenseVector{Float64}, Y::DenseVector{Complex128}) =
jl_fftw_plan_dft_r2c_1d(X::Vector{Float64}, Y::Vector{Complex128}) =
ccall(dlsym(libfftw, :fftw_plan_dft_r2c_1d),
Ptr{Void},
(Int32, Ptr{Float64}, Ptr{Complex128}, Uint32, ),
int32(length(X)), X, Y, FFTW_ESTIMATE)

jl_fftw_plan_dft_r2c_1d(X::DenseVector{Float32}, Y::DenseVector{Complex64}) =
jl_fftw_plan_dft_r2c_1d(X::Vector{Float32}, Y::Vector{Complex64}) =
ccall(dlsym(libfftw, :fftwf_plan_dft_r2c_1d),
Ptr{Void},
(Int32, Ptr{Float32}, Ptr{Complex64}, Uint32, ),
int32(length(X)), X, Y, FFTW_ESTIMATE)

# Create 2d plan

jl_fftw_plan_dft_2d(X::DenseMatrix{Complex128}, Y::DenseMatrix{Complex128}, direction::Int32) =
jl_fftw_plan_dft_2d(X::Matrix{Complex128}, Y::Matrix{Complex128}, direction::Int32) =
ccall(dlsym(libfftw, :fftw_plan_dft_2d),
Ptr{Void},
(Int32, Int32, Ptr{Complex128}, Ptr{Complex128}, Int32, Uint32, ),
int32(size(X,2)), int32(size(X,1)), X, Y, direction, FFTW_ESTIMATE)

jl_fftw_plan_dft_2d(X::DenseMatrix{Complex64}, Y::DenseMatrix{Complex64}, direction::Int32) =
jl_fftw_plan_dft_2d(X::Matrix{Complex64}, Y::Matrix{Complex64}, direction::Int32) =
ccall(dlsym(libfftwf, :fftwf_plan_dft_2d),
Ptr{Void},
(Int32, Int32, Ptr{Complex64}, Ptr{Complex64}, Int32, Uint32, ),
Expand Down Expand Up @@ -109,29 +109,27 @@ jl_fftw_plan_dft(X::Array{Complex64}, Y::Array{Complex64}, direction::Int32) =

macro fftw_fftn(fname, array_type, in_type, plan_name, direction)
quote

function ($fname)(X::($array_type){$in_type})
Y = similar(X, $in_type)
plan = ($plan_name)(X, Y, $direction)
jl_fftw_execute($in_type, plan)
jl_fftw_destroy_plan($in_type, plan)
return Y
end

end
end

@fftw_fftn fft DenseVector Complex128 jl_fftw_plan_dft_1d FFTW_FORWARD
@fftw_fftn ifft DenseVector Complex128 jl_fftw_plan_dft_1d FFTW_BACKWARD
@fftw_fftn fft Vector Complex128 jl_fftw_plan_dft_1d FFTW_FORWARD
@fftw_fftn ifft Vector Complex128 jl_fftw_plan_dft_1d FFTW_BACKWARD

@fftw_fftn fft DenseVector Complex64 jl_fftw_plan_dft_1d FFTW_FORWARD
@fftw_fftn ifft DenseVector Complex64 jl_fftw_plan_dft_1d FFTW_BACKWARD
@fftw_fftn fft Vector Complex64 jl_fftw_plan_dft_1d FFTW_FORWARD
@fftw_fftn ifft Vector Complex64 jl_fftw_plan_dft_1d FFTW_BACKWARD

@fftw_fftn fft2 DenseMatrix Complex128 jl_fftw_plan_dft_2d FFTW_FORWARD
@fftw_fftn ifft2 DenseMatrix Complex128 jl_fftw_plan_dft_2d FFTW_BACKWARD
@fftw_fftn fft2 Matrix Complex128 jl_fftw_plan_dft_2d FFTW_FORWARD
@fftw_fftn ifft2 Matrix Complex128 jl_fftw_plan_dft_2d FFTW_BACKWARD

@fftw_fftn fft2 DenseMatrix Complex64 jl_fftw_plan_dft_2d FFTW_FORWARD
@fftw_fftn ifft2 DenseMatrix Complex64 jl_fftw_plan_dft_2d FFTW_BACKWARD
@fftw_fftn fft2 Matrix Complex64 jl_fftw_plan_dft_2d FFTW_FORWARD
@fftw_fftn ifft2 Matrix Complex64 jl_fftw_plan_dft_2d FFTW_BACKWARD

@fftw_fftn fft3 Array{Complex128,3} Complex128 jl_fftw_plan_dft_3d FFTW_FORWARD
@fftw_fftn ifft3 Array{Complex128,3} Complex128 jl_fftw_plan_dft_3d FFTW_BACKWARD
Expand All @@ -147,7 +145,6 @@ end

macro fftw_fftn_real(fname, array_type, in_type, out_type, plan_name)
quote

function ($fname)(X::($array_type){$in_type})
Y = similar(X, $out_type)
plan = ($plan_name)(X, Y)
Expand All @@ -162,16 +159,15 @@ macro fftw_fftn_real(fname, array_type, in_type, out_type, plan_name)

return Y
end

end
end

@fftw_fftn_real fft DenseVector Float64 Complex128 jl_fftw_plan_dft_r2c_1d
@fftw_fftn_real fft DenseVector Float32 Complex64 jl_fftw_plan_dft_r2c_1d
@fftw_fftn_real fft Vector Float64 Complex128 jl_fftw_plan_dft_r2c_1d
@fftw_fftn_real fft Vector Float32 Complex64 jl_fftw_plan_dft_r2c_1d

# TODO: Implement efficient operations such as the vector case later
fft2(X::Union(DenseMatrix{Float64}, DenseMatrix{Float32})) = fft2(complex(X))
fft3(X::Union(Array{Float64,3}, Array{Float32,3})) = fft3(complex(X))
fftn(X::Union(Array{Float64}, Array{Float32})) = fftn(complex(X))
fft2(X::Union(Matrix{Float64}, Matrix{Float32})) = fft2(complex(X))
fft3(X::Union(Array{Float64,3}, Array{Float32,3})) = fft3(complex(X))
fftn(X::Union(Array{Float64}, Array{Float32})) = fftn(complex(X))

# TODO: Compute fft and ifft of slices of arrays
22 changes: 11 additions & 11 deletions j/linalg_blas.j
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ macro blas_copy(fname, shape, eltype)
end
end

@blas_copy :dcopy_ DenseVector Float64
@blas_copy :scopy_ DenseVector Float32
@blas_copy :dcopy_ DenseMatrix Float64
@blas_copy :scopy_ DenseMatrix Float32
@blas_copy :zcopy_ DenseVector Complex128
@blas_copy :ccopy_ DenseVector Complex64
@blas_copy :zcopy_ DenseMatrix Complex128
@blas_copy :ccopy_ DenseMatrix Complex64
@blas_copy :dcopy_ Vector Float64
@blas_copy :scopy_ Vector Float32
@blas_copy :dcopy_ Matrix Float64
@blas_copy :scopy_ Matrix Float32
@blas_copy :zcopy_ Vector Complex128
@blas_copy :ccopy_ Vector Complex64
@blas_copy :zcopy_ Matrix Complex128
@blas_copy :ccopy_ Matrix Complex64

# DOUBLE PRECISION FUNCTION DDOT(N,DX,INCX,DY,INCY)

macro blas_dot(fname, eltype)
quote
function dot(x::DenseVector{$eltype}, y::DenseVector{$eltype})
function dot(x::Vector{$eltype}, y::Vector{$eltype})
ccall(dlsym(libBLAS, $fname),
$eltype,
(Ptr{Int32}, Ptr{$eltype}, Ptr{Int32}, Ptr{$eltype}, Ptr{Int32}),
Expand All @@ -48,7 +48,7 @@ end

macro blas_norm(fname, eltype, ret_type)
quote
function norm(x::DenseVector{$eltype})
function norm(x::Vector{$eltype})
ccall(dlsym(libBLAS, $fname),
$ret_type,
(Ptr{Int32}, Ptr{$eltype}, Ptr{Int32}),
Expand All @@ -72,7 +72,7 @@ end

macro blas_matrix_multiply(fname, eltype)
quote
function *(A::DenseVecOrMat{$eltype}, B::DenseVecOrMat{$eltype})
function *(A::VecOrMat{$eltype}, B::VecOrMat{$eltype})
m = size(A, 1)
if isa(B, Vector); n = 1; else n = size(B, 2); end
if isa(A, Vector); k = 1; else k = size(A, 2); end
Expand Down
20 changes: 10 additions & 10 deletions j/linalg_lapack.j
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ libLAPACK = libBLAS

macro lapack_chol(fname, eltype)
quote
function chol(A::DenseMatrix{$eltype})
function chol(A::Matrix{$eltype})
info = [int32(0)]
n = int32(size(A, 1))
R = triu(A)
Expand Down Expand Up @@ -38,11 +38,11 @@ end
# INTEGER IPIV( * )
# DOUBLE PRECISION A( LDA, * )

lu(A::DenseMatrix) = lu(A, false)
lu(A::Matrix) = lu(A, false)

macro lapack_lu(fname, eltype)
quote
function lu(A::DenseMatrix{$eltype}, economy::Bool)
function lu(A::Matrix{$eltype}, economy::Bool)
info = [int32(0)]
m, n = size(A)
LU = A
Expand Down Expand Up @@ -96,7 +96,7 @@ end

macro lapack_qr(fname, fname2, eltype)
quote
function qr(A::DenseMatrix{$eltype})
function qr(A::Matrix{$eltype})
info = [int32(0)]
m, n = size(A)
QR = copy(A)
Expand Down Expand Up @@ -171,7 +171,7 @@ end

macro lapack_qr_complex(fname, fname2, eltype, eltype2)
quote
function qr(A::DenseMatrix{$eltype})
function qr(A::Matrix{$eltype})
info = [int32(0)]
m, n = size(A)
QR = copy(A)
Expand Down Expand Up @@ -240,7 +240,7 @@ end

macro lapack_eig(fname, eltype)
quote
function eig(A::DenseMatrix{$eltype})
function eig(A::Matrix{$eltype})
if !issymmetric(A); error("Matrix must be symmetric"); end

jobz = "V"
Expand Down Expand Up @@ -288,7 +288,7 @@ end
# COMPLEX*16 A( LDA, * ), WORK( * )
macro lapack_eig_complex(fname, eltype, eltype2)
quote
function eig(A::DenseMatrix{$eltype})
function eig(A::Matrix{$eltype})
if !ishermitian(A); error("Matrix must be Hermitian"); end

jobz = "V"
Expand Down Expand Up @@ -337,7 +337,7 @@ end

macro lapack_svd(fname, eltype)
quote
function svd(A::DenseMatrix{$eltype})
function svd(A::Matrix{$eltype})
jobu = "A"
jobvt = "A"
m, n = size(A)
Expand Down Expand Up @@ -395,7 +395,7 @@ end

macro lapack_svd_complex(fname, eltype, eltype2)
quote
function svd(A::DenseMatrix{$eltype})
function svd(A::Matrix{$eltype})
jobu = "A"
jobvt = "A"
m, n = size(A)
Expand Down Expand Up @@ -463,7 +463,7 @@ end

macro lapack_backslash(fname_lu, fname_chol, fname_lsq, fname_tri, eltype)
quote
function \(A::DenseMatrix{$eltype}, B::DenseVecOrMat{$eltype})
function \(A::Matrix{$eltype}, B::VecOrMat{$eltype})
info = [int32(0)]
m = int32(size(A, 1))
n = int32(size(A, 2))
Expand Down
2 changes: 1 addition & 1 deletion j/random.j
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ srand(seed::Uint32) = (ccall(dlsym(libmt, :dsfmt_gv_init_gen_rand), Void, (Uint3

srand(seed::Uint64) = srand([uint32(seed),uint32(seed>>32)])

function srand(seed::DenseVector{Uint32})
function srand(seed::Vector{Uint32})
ccall(dlsym(libmt, :dsfmt_gv_init_by_array),
Void, (Ptr{Uint32}, Int32),
seed, int32(length(seed)))
Expand Down
6 changes: 3 additions & 3 deletions j/tensor.j
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

typealias AbstractVector{T} Tensor{T,1}
typealias AbstractMatrix{T} Tensor{T,2}
typealias DenseVector{T} Array{T,1}
typealias DenseMatrix{T} Array{T,2}
typealias DenseVecOrMat{T} Union(DenseVector{T}, DenseMatrix{T})
typealias Vector{T} Array{T,1}
typealias Matrix{T} Array{T,2}
typealias VecOrMat{T} Union(Vector{T}, Matrix{T})

typealias Indices{T<:Int} Union(Int, AbstractVector{T})
typealias Region Union(Size,Dims)
Expand Down

0 comments on commit 26b8497

Please sign in to comment.