From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id MAA14059 for caml-redistribution; Fri, 9 Jun 1995 12:03:37 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id JAA10531 for ; Fri, 9 Jun 1995 09:29:44 +0200 Received: from vink.Univ-Angers.Fr (vink.univ-angers.fr [193.49.144.8]) by nez-perce.inria.fr (8.6.10/8.6.9) with ESMTP id JAA26585 for ; Fri, 9 Jun 1995 09:29:42 +0200 Received: (from pn@localhost) by vink.Univ-Angers.Fr (8.6.9/8.6.9) id JAA03487 for caml-list@pauillac.inria.fr; Fri, 9 Jun 1995 09:29:41 +0200 From: Pascal Nicolas Message-Id: <199506090729.JAA03487@vink.Univ-Angers.Fr> Subject: Re: vector dot multiply To: caml-list@pauillac.inria.fr (Liste de diffusion Caml) Date: Fri, 9 Jun 95 9:29:41 METDST In-Reply-To: <199506081716.NAA01690@thomas.ge.com>; from "U-E59264-Osman Buyukisik" at Jun 8, 95 1:16 pm Mailer: Elm [revision: 70.85] Sender: weis > > 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