caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pascal Nicolas <pn@univ-angers.fr>
To: caml-list@pauillac.inria.fr (Liste de diffusion Caml)
Subject: Re: vector dot multiply
Date: Fri, 9 Jun 95 9:29:41 METDST	[thread overview]
Message-ID: <199506090729.JAA03487@vink.Univ-Angers.Fr> (raw)
In-Reply-To: <199506081716.NAA01690@thomas.ge.com>; from "U-E59264-Osman Buyukisik" at Jun 8, 95 1:16 pm

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 902 bytes --]

> 
> Hi,
>  What would be 1). elegant
>                2). efficient  
>  way to write a "dot multiply" function in caml-light? 
> This is what I came up with but I am hoping for a better one :
> 
> let dot a b = let rec dot_aux a b i sum =
> if i< vect_length a then
>    dot_aux a b (i+1) (sum +. (a.(i) *. b.(i)) )
>  else
>    sum
> in
>  dot_aux a b 0 0.0;;
> 
In order to avoid to (re)compute the length of a at each recursive call, you
can modify a little your function as follows

 let dot a b = let rec dot_aux a b i sum L =
 if i < L then
    dot_aux a b (i+1) (sum +. (a.(i) *. b.(i))) L
 else
    sum
 in dot_aux a b 0 0.0 (vect_length a) ;;


--
Pascal NICOLAS                                       LERIA  Université d'ANGERS
Tél : (33) 41 73 54 20             2, Bd Lavoisier 49045 ANGERS cedex 01 FRANCE
E Mail : pn@univ-angers.fr
WWW Url : http://www.univ-angers.fr/~pn/nicolas.html




  parent reply	other threads:[~1995-06-09 10:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-06-08 17:16 U-E59264-Osman Buyukisik
1995-06-08 18:29 ` Pierre Weis
1995-06-08 23:02 ` Ascander Suarez
1995-06-08 23:17 ` Bob Buckley
1995-06-09  7:29 ` Pascal Nicolas [this message]
1995-06-09 10:42   ` Judicael Courant
1995-06-09 11:50 Chet Murthy
1995-06-09 13:20 ` nikhil

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=199506090729.JAA03487@vink.Univ-Angers.Fr \
    --to=pn@univ-angers.fr \
    --cc=caml-list@pauillac.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;
as well as URLs for NNTP newsgroup(s).