diff --git a/base/exports.jl b/base/exports.jl index ea14ae36e8d98..5b153f7b3ae9b 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -632,6 +632,7 @@ export cond, condskeel, cross, + ctranspose!, ctranspose, det, diag, @@ -692,6 +693,7 @@ export svdvals, sylvester, trace, + transpose!, transpose, tril!, tril, diff --git a/base/sparse.jl b/base/sparse.jl index 87c381af430aa..3e144fa60aa1b 100644 --- a/base/sparse.jl +++ b/base/sparse.jl @@ -4,6 +4,7 @@ module SparseMatrix importall Base import Base.NonTupleType, Base.float, Base.Order, Base.Sort.Forward +import Base.transpose!, Base.ctranspose! export SparseMatrixCSC, blkdiag, dense, diag, diagm, droptol!, dropzeros!, etree, full, diff --git a/base/sparse/csparse.jl b/base/sparse/csparse.jl index 16cc05526d9cc..2cd1816f461a7 100644 --- a/base/sparse/csparse.jl +++ b/base/sparse/csparse.jl @@ -123,7 +123,7 @@ end # Based on Direct Methods for Sparse Linear Systems, T. A. Davis, SIAM, Philadelphia, Sept. 2006. # Section 2.5: Transpose # http://www.cise.ufl.edu/research/sparse/CSparse/ -function transpose!{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, T::SparseMatrixCSC{Tv,Ti}) +function transpose!{Tv,Ti}(T::SparseMatrixCSC{Tv,Ti}, S::SparseMatrixCSC{Tv,Ti}) (mS, nS) = size(S) nnzS = nnz(S) colptr_S = S.colptr @@ -162,10 +162,10 @@ function transpose{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}) nzval_T = Array(Tv, nnzS) T = SparseMatrixCSC(mT, nT, colptr_T, rowval_T, nzval_T) - return transpose!(S, T) + return transpose!(T, S) end -function ctranspose!{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, T::SparseMatrixCSC{Tv,Ti}) +function ctranspose!{Tv,Ti}(T::SparseMatrixCSC{Tv,Ti}, S::SparseMatrixCSC{Tv,Ti}) (mS, nS) = size(S) nnzS = nnz(S) colptr_S = S.colptr @@ -204,7 +204,7 @@ function ctranspose{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}) nzval_T = Array(Tv, nnzS) T = SparseMatrixCSC(mT, nT, colptr_T, rowval_T, nzval_T) - return ctranspose!(S, T) + return ctranspose!(T, S) end # Compute the elimination tree of A using triu(A) returning the parent vector. diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index c0fadc45b39e6..0613faf9345fb 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -2067,8 +2067,8 @@ function sortSparseMatrixCSC!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}; sortindices::Sym if sortindices == :doubletranspose nB, mB = size(A) B = SparseMatrixCSC(mB, nB, Array(Ti, nB+1), similar(A.rowval), similar(A.nzval)) - transpose!(A, B) transpose!(B, A) + transpose!(A, B) return A end diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 210dd3c5fa1e9..b0cf467def808 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -4313,6 +4313,10 @@ Indexing, Assignment, and Concatenation Like :func:`permutedims`, except the inverse of the given permutation is applied. +.. function:: permutedims!(dest,src,perm) + + Permute the dimensions of array ``src`` and store the result in the array ``dest``. ``perm`` is a vector specifying a permutation of length ``ndims(src)``. The preallocated array ``dest`` should have ``size(dest)=size(src)[perm]`` and is completely overwritten. No in-place permutation is supported and unexpected results will happen if `src` and `dest` have overlapping memory regions. + .. function:: squeeze(A, dims) Remove the dimensions specified by ``dims`` from array ``A`` diff --git a/doc/stdlib/linalg.rst b/doc/stdlib/linalg.rst index 1b39832b90056..5bec267b1f210 100644 --- a/doc/stdlib/linalg.rst +++ b/doc/stdlib/linalg.rst @@ -552,10 +552,18 @@ Linear algebra functions in Julia are largely implemented by calling functions f The transposition operator (``.'``). +.. function:: transpose!(dest,src) + + Transpose array ``src`` and store the result in the preallocated array ``dest``, which should have a size corresponding to ``(size(src,2),size(src,1))``. No in-place transposition is supported and unexpected results will happen if `src` and `dest` have overlapping memory regions. + .. function:: ctranspose(A) The conjugate transposition operator (``'``). +.. function:: ctranspose!(dest,src) + + Conjugate transpose array ``src`` and store the result in the preallocated array ``dest``, which should have a size corresponding to ``(size(src,2),size(src,1))``. No in-place transposition is supported and unexpected results will happen if `src` and `dest` have overlapping memory regions. + .. function:: eigs(A, [B,]; nev=6, which="LM", tol=0.0, maxiter=1000, sigma=nothing, ritzvec=true, v0=zeros((0,))) -> (d,[v,],nconv,niter,nmult,resid) ``eigs`` computes eigenvalues ``d`` of ``A`` using Lanczos or Arnoldi iterations for real symmetric or general nonsymmetric matrices respectively. If ``B`` is provided, the generalized eigen-problem is solved. The following keyword arguments are supported: