From: Nicolas FRANCOIS (AKA El Bofo) <nicolas.francois@free.fr>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Side effect
Date: Fri, 9 Aug 2002 00:40:20 +0200 [thread overview]
Message-ID: <20020809004020.1dace6b2.nicolas.francois@free.fr> (raw)
Thanks for the tip on stdout, I found the problem. Ocamldebug had me
discover another bug (a copy-paste bug ;-), but I'm stuck on this one :
let cherche_pivot m fllig flcol =
try
for i = 0 to D.lignes - 1 do
if fllig.(i)
then
for j = 0 to D.colonnes - 1 do
if flcol.(j)
then
if A.(==) m.(i).(j) A.zero
then ()
else raise (Pivot_trouve (i,j))
done
done;
raise Plus_de_pivot
with Pivot_trouve (i,j) -> (i,j)
let applique_pivot_ligne m fllig flcol i j div =
let m' = Array.copy m
and x = m.(i).(j)
in
for i' = 0 to D.lignes - 1 do
if fllig.(i')
then
let y = m'.(i').(j) in
for j' = 0 to D.colonnes - 1 do
if flcol.(j')
then m'.(i').(j') <-
A.(//) (A.(--)
(A.( ** ) x m'.(i').(j'))
(A.( ** ) y m'.(i).(j'))) div
done;
m'.(i').(j) <- A.zero;
done;
m'
let pivot_ligne_sans_echange m =
let m' = Array.copy m
and fllig = Array.make D.lignes true
and flcol = Array.make D.colonnes true
and divisor = A.one
in
let rec plse_aux mat fl fc div =
try
let (i,j) = cherche_pivot mat fl fc
in
fl.(i) <- false;
fc.(j) <- false;
let mat' = applique_pivot_ligne mat fl fc i j div in
plse_aux mat' fl fc mat'.(i).(j)
with Plus_de_pivot -> mat
in
plse_aux m' fllig flcol A.one
end
It's just a fraction free Gauss reduction without lines exchanges. It
works :
let m = Matrice_Z.parse
(Stream.of_string
"[[ 3, 4, -2, 1, -2],[ 1, -1, 2, 2, 7],[ 4, -3, 4, -3, 2],[ -1, 1,
6, -1, 1]]");;
Matrice_Z.print m;;
prints
( 3 4 -2 1 -2 )
( 1 -1 2 2 7 )
( 4 -3 4 -3 2 )
( -1 1 6 -1 1 )
let m' = Pivot_Z.pivot_ligne_sans_echange m;;
Matrice_Z.print m';;
gives the correct
( 3 4 -2 1 -2 )
( 0 -7 8 5 23 )
( 0 0 20 72 159 )
( 0 0 0 -556 -1112 )
Trouble is
Matrice_Z.print m';;
answers
( 3 4 -2 1 -2 )
( 0 -7 8 5 23 )
( 0 0 20 72 159 )
( 0 0 0 -556 -1112 )
So matrix m was modified. But I work on a copy of m in
Pivot_Z.pivot_ligne_sans_echange. What's the problem doc ?
\bye
--
Nicolas FRANCOIS
http://nicolas.francois.free.fr
A TRUE Klingon programmer does NOT comment his code
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next reply other threads:[~2002-08-08 22:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-08 22:40 Nicolas FRANCOIS [this message]
2002-08-09 6:43 ` Florian Hars
2002-08-09 11:27 ` Nicolas FRANCOIS
2002-08-09 12:08 ` Pierre Weis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020809004020.1dace6b2.nicolas.francois@free.fr \
--to=nicolas.francois@free.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox