I have played around with matrix over paths in a graph. I use vectors (functor,
arg, setarg, nb_setarg), and forall/2. I am not familiar with these builtins,
but I feel comfortable. Although I noticed that forall/2 unbinds vriables, when
I met unexpected results. So then nb_setarg ! Fortunately, I have no other problems
so far. nb_setarg/3 looks efficient.
The sample below is: create new matrix with 1000 x 1000 dimension with
initialial elements, and then transpose it. Time statistics looks not so bad.
Codes of new_marix/2 and m_transopse are also below.
?- time(( Dim = 1000-1000, new_matrix(Dim, M),
forall((between(1, W, I), between(1, H, J)),
m_nb_setarg(I, J, M, p(I, J))),
m_transpose(M, Tr_of_M))).
% 9,015,017 inferences, 0.555 CPU in 0.578 seconds (96% CPU, 16249305 Lips)
Dim = 1000-1000,
M = #(..),
Tr_of_M = #(..).
?- new_matrix(2-3, M), writeln(M).
#(#(_64304874,_64304880,_64304886),#(_64304906,_64304912,_64304918))
M = #(..).
%
new_matrix(W-H, Matrix):- length(M0, W),
maplist(pred(H, ([C]:- length(R, H), C=..[#|R])), M0),
Matrix=..[#|M0].
%
m_transpose(X, Y):- atom(X), !, Y = X.
m_transpose(X, Y):- dim(X, W-H), % W>0.
new_matrix(H-W, Y),
forall( between(1, H, I),
( arg(I, Y, V),
forall( between(1, W, J),
( m_arg(J, I, X, Aji),
nb_setarg(J, V, Aji)
))
)
).
I will appreciate if expert on matirix handling in Prolog suggests anything or
his experience. My current interest is to handle matrix over family of zdd of
path sets in a graph. I am not sure it will work, nevertheless there are several
things I would like to try before I would be too much tired for unknown possible
difficulty which I have not seen yet.
Kuniaki Mukai