From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Llorens Newsgroups: gmane.lisp.guile.devel Subject: Re: propose deprecation of generalized-vector-* Date: Wed, 19 Sep 2012 19:20:49 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1348075270 12920 80.91.229.3 (19 Sep 2012 17:21:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Sep 2012 17:21:10 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Sep 19 19:21:15 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TENxW-0004sL-BE for guile-devel@m.gmane.org; Wed, 19 Sep 2012 19:21:10 +0200 Original-Received: from localhost ([::1]:57993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TENxS-0003qk-0r for guile-devel@m.gmane.org; Wed, 19 Sep 2012 13:21:06 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TENxL-0003ja-B0 for guile-devel@gnu.org; Wed, 19 Sep 2012 13:21:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TENxG-000394-VG for guile-devel@gnu.org; Wed, 19 Sep 2012 13:20:59 -0400 Original-Received: from zhbdzmsp-smta15.bluewin.ch ([195.186.99.132]:34925) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TENxG-00038G-Oy for guile-devel@gnu.org; Wed, 19 Sep 2012 13:20:54 -0400 Original-Received: from [195.186.227.131] ([195.186.227.131:33748] helo=zhhdzmsp-smta14.bluewin.ch) by zhbdzmsp-smta15.bluewin.ch (envelope-from ) (ecelerity 2.2.3.47 r(39824M)) with ESMTP id 98/9F-21421-3FEF9505; Wed, 19 Sep 2012 17:20:51 +0000 Original-Received: from [10.23.3.35] (128.179.67.121) by zhhdzmsp-smta14.bluewin.ch (8.5.142) (authenticated as dll@bluewin.ch) id 5058744B0013D32F for guile-devel@gnu.org; Wed, 19 Sep 2012 17:20:51 +0000 In-Reply-To: X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.186.99.132 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:14902 Archived-At: On Sep 19, 2012, at 18:00, guile-devel-request@gnu.org wrote: > Date: Wed, 19 Sep 2012 13:02:25 +0100 > From: Peter TB Brett > To: guile-devel@gnu.org > Subject: Re: propose deprecation of generalized-vector-* ... > It seems to me that array-length should return the first non-unity > dimension. This is the approach taken by e.g. MATLAB's length() > function. It would give it a distinct utility compared to > array-dimensions (which is analogous to MATLAB's size() function). >=20 > WDYT? >=20 > Peter That is not exactly what length() does in Matlab: > >> help length > LENGTH Length of vector. > LENGTH(X) returns the length of vector X. It is equivalent > to MAX(SIZE(X)) for non-empty arrays and 0 for empty ones. The notion of rank in Matlab is rather sui generis. There are no rank 1 = objects as such, only row or column vectors. Even size(0) gives [1 1]. = So there's constant confusion when you want a simple vector X, because = Matlab gives you a column or a row and you need to know which one you've = got, even though the things you want to do with X don't depend on that = at all. That leads to superfluous use of (:) and .' . The above definition of length() is meant to paper over the row/column = distinction. Octave says: > octave:1> help length > `length' is a built-in function >=20 > -- Built-in Function: length (A) > Return the `length' of the object A. For matrix objects, the > length is the number of rows or columns, whichever is greater = (this > odd definition is used for compatibility with MATLAB). Guile is strict about rank, so this problem doesn't exist. Wouldn't you = agree? ---- Going back to the two definitions I proposed, and after giving it some = thought, I favor the first (array-length a) =3D (car (array-dimensions a)) more strongly than before, for these reasons: 1. Utility. I do the equivalent of (car (array-dimensions a)) much more = often than either (fold * 1 (array-dimensions a)) or what Matlab = length() does. An array is often also a list of objects, e.g. a list of = n points in R^m is an [n m] shape array, or a list of n transformation = matrices is an [n m m] shape array [*]. Of course this is because of the way I use arrays in my own code. I'd be = interested in reading about what other people do. =20 2. Efficiency. (car (array-dimensions a)) deserves a shortcut, since = it's a waste to construct a list only to take its car. You can say that = of the other axes, but the first axis is used more often. [*] This is very common in J and K, the descendants of APL. In fact K's = 'arrays' don't even need to be rectangular. But I think J can be a good = model for Guile arrays. J has an operator '#' (tally) which is basically = what I propose for array-length. The only difference is that in J (# = scalar) gives 1, and this seems irregular. It maybe better to make = (array-length #0(0)) an error. Here's an implementation with this behavior. SCM array_length(SCM a) { scm_t_array_handle h; scm_array_get_handle(a, &h); if (scm_array_handle_rank(&h)=3D=3D0) { scm_array_handle_release(&h); scm_error_scm(scm_from_locale_symbol("out-of-range"), = SCM_BOOL_F, scm_from_locale_string("no items for rank 0 = array"), SCM_EOL, a); } scm_t_array_dim const * dims =3D scm_array_handle_dims(&h); SCM l =3D scm_from_size_t(dims->ubnd-dims->lbnd+1); scm_array_handle_release(&h); return l; }