>>> The disadvantage, however, is that can sometimes require a lot of memory--especially if you don't have a good pre-conditioner.Benjamin, could you please explain how the quality of the pre-conditioner increases memory usage?
The iterative methods in c++ library can be easily translated to Julia....
I can start a package for this if enough people are interested..
Hari
I think that our language features should allow for a much nicer interface to the various solvers than matlab. The hard work is going to be the preconditioners and we will need to use stuff like petsc or other packages there.
-viral
I think these interfaces and code should mature outside base for now. Eventually the common solvers and preconditioners should be in base.
-viral
[BTW, what is the preferred method for sending patches that does *not* involve centralizing on github? I have far too many accounts. My little patches aren't enough to justify getting yet another account.]
What functions/operations are expected from a subclass of AbstractMatrix? (You're more experienced with Julia than I am.) If the expectation (or implicit policy) is that all subclasses of AbstractMatrix support more operators than just matrix multiplication, then I worry that this could cause issues with other Julia packages or client code that has structured it's methods around a stricter usage of the type hierarchy.
import Base: size, issym, ishermitian
type CPM{T<:Base.LinAlg.BlasFloat}<:AbstractMatrix{T} # completely positive map kraus::Array{T,3} # kraus operator representationend
size(Phi::CPM)=(size(Phi.kraus,1)^2,size(Phi.kraus,3)^2)issym(Phi::CPM)=falseishermitian(Phi::CPM)=false
function *{T<:Base.LinAlg.BlasFloat}(Phi::CPM{T},rho::Vector{T}) rho=reshape(rho,(size(Phi.kraus,3),size(Phi.kraus,3))) rho2=zeros(T,(size(Phi.kraus,1),size(Phi.kraus,1))) for s=1:size(Phi.kraus,2) As=slice(Phi.kraus,:,s,:) rho2+=As*rho*As' end return reshape(rho2,(size(Phi.kraus,1)^2,))end
x = rand(1000,2);
y = Array(Array{Float64,1},2);
y[1] = rand(1000);
y[2] = rand(1000);
z = rand(1000);
tic();
for i = 1:1e6
a = dot(x,y[1]);
end
toc();
#elapsed time: 0.529180537 seconds
for i = 1:1e6
a = dot(x,subs(z,1:1000,1));
end
toc();
#elapsed time: 6.843639198 seconds
A = rand(1000,1000);
L(x) = *(A,x);
b = rand(1000);
x1 = gmres(A,b);
x2 = gmres(L,b);
Also, in order to get good performance, as we go ahead with iterative solvers, we need fast sparse matvec.
I am thinking of plugging in Rich Vuduc's OSKI library. Not sure if it is maintained or if there are replacements.
-viral
Perhaps we need a LinearOperator abstraction above AbstractMatrix
But allowing linear solvers or eigensolvers to accept generic functions as argument, certainly sounds like a bad idea to me. You loose any possibility of encoding specific information of the AbstractMatrix/LinearOperator in the concrete type of the argument that you pass to the solver. This means that, like in matlab, you have to specify via additional arguments what the dimension of the vector space on which it acts, whether it is symmetric (or hermitian), etc. This does not fit within the philosophy of Julia's type system or of object-oriented design, where the solver in question should be able to extract these properties from the central argument (being the linear operator / abstract matrix) directly and the method dispatch system together with a well implemented user's type (which overloads the corresponding methods) makes everything work correctly.
I really don't understand the need to declare a type here at all. The *only* reason to declare a type in Julia is if you need to dispatch on it to distinguish it from other types. Since eigs and GMRES are inherently only for linear operators, why must a matrix type be specified explicitly? What's wrong with duck typing here?
On Saturday, October 12, 2013 2:56:30 PM UTC-4, Stefan Karpinski wrote:Perhaps we need a LinearOperator abstraction above AbstractMatrix
We can't put this "above" AbstractMatrix because AbstractMatrix is already a subtype of AbstractArray, and Julia doesn't support multiple inheritance.
My basic problem is that AbstractArray, if it means anything at all, means an indexable container. i.e. an abstract matrix M should support M[i,j] if nothing else; while this can certainly be supported for arbitrary (finite-dimensional) linear operators (in a given basis), it may be extremely inefficient if the operator is stored implicitly.
For example, Julia already uses "iterable" types extensively in its standard library, which is any type that implements next, start, and end functions rather than a type per se.
As another example, the quadgk integration function works on any type that supports +, -, * by scalar, and norm. That is, for any normed vector space...despite the fact that Julia does not have an abstract type for this.