From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Cowan Newsgroups: gmane.lisp.guile.user Subject: Re: Matrix or array operations library Date: Thu, 27 Dec 2018 16:24:29 -0500 Message-ID: References: <2FB4CE72-80C9-46CE-B33F-8D133CD77A84@bluewin.ch> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1545945795 21913 195.159.176.226 (27 Dec 2018 21:23:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 27 Dec 2018 21:23:15 +0000 (UTC) Cc: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Dec 27 22:23:11 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gcd7V-0005Yr-UU for guile-user@m.gmane.org; Thu, 27 Dec 2018 22:23:10 +0100 Original-Received: from localhost ([127.0.0.1]:55294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gcd9c-0008Ca-Bk for guile-user@m.gmane.org; Thu, 27 Dec 2018 16:25:20 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:48252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gcd91-0008CQ-Rn for guile-user@gnu.org; Thu, 27 Dec 2018 16:24:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gcd90-00086c-Jv for guile-user@gnu.org; Thu, 27 Dec 2018 16:24:43 -0500 Original-Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:40808) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gcd90-000864-AQ for guile-user@gnu.org; Thu, 27 Dec 2018 16:24:42 -0500 Original-Received: by mail-wr1-x42e.google.com with SMTP id p4so19379301wrt.7 for ; Thu, 27 Dec 2018 13:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ccil-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc; bh=Wh5AoX6KsepkLTl6YEvDAGJB/ujbVRLEn7EM8h9bd6E=; b=gytBsIm+RXk/4csu2GWJGl+xLULpCk5xemrOcQTaI9Q8h0A+Few+9Z5a03sipp1QYE 2Pbj1XdbBfiJB3LH5AToFMGCuUSLLLEej0Mbm6hUFj+iPfnIjtL07Bksy5gyQ3hBUrx2 wglPjhF9TVSUwOrnM1dgTICillvjCFHVsiUIsCFTKFfdnfiVw5XJIFiSAedI+Qj/g5Cm 18ZZhS/Wpo/HaZgZfn2xOcnGNv1KyTEVAcyxwpUDYqlRX59m99jcCwcNtTaf2nTOHxD5 7IWSBWbbrF5C6GTHD//CfThewDE99XnYBvXmeD1AkCT/r3a2LvC6YzAmFDsoTRnI8O9B QN2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:cc; bh=Wh5AoX6KsepkLTl6YEvDAGJB/ujbVRLEn7EM8h9bd6E=; b=fjHOlM8oyyotEj7abL9tPwl+7WaaGRnmnrdrQCXvd5kZQENwMBA/ziMqAvD1wjaFVR phkQ1wDSzYFZWFJcSFvEnJ0dj/nXN1xnRhC1wuoHmux/QBnwaLD3ZQ4SFMGvWUCOezUC WQDmlcQSOlDmwYoDpfAsfKY/V8k64H61eybhggq6neM3uJFrcZxSd9GDTi6M898NT6i9 FfbPWZj89pJvx2V39Efh8QnBbkB5yHlDYBDtHin725Ac9i/B+9iqyQxbx/snzBZlHeTa 7SDNxuiX3ekobInPcL1FVUPNg30u2BhkqGdH3/qXIxATeWLj3D2Az4BohY4CP31NG/Ml 6TFA== X-Gm-Message-State: AJcUukeHq3w4QNYgYwdFwsyIhoSKj4Q7urz5ndv/geNS1T8PMW0+Kj8k pOnENIb2NbBZ1CjFmnKbq9s150RqWWydAAzHI95egmXdp7kUNA== X-Google-Smtp-Source: ALg8bN5wdYpkjiLUeR3pxDvkCifRvQb3LbdiOo5TRo80lkm64rpSjvDx7NEQEovBOwmke8oTdC0srKGrFnD4/3Kpfas= X-Received: by 2002:adf:91c3:: with SMTP id 61mr22532581wri.324.1545945880430; Thu, 27 Dec 2018 13:24:40 -0800 (PST) In-Reply-To: <2FB4CE72-80C9-46CE-B33F-8D133CD77A84@bluewin.ch> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:15156 Archived-At: > > >> With regard to NumPy, especially the stuff about the "strides" (whatever > >> that is) > Strides are an extremely powerful concept that allow transformations to be done on arrays without actually moving or changing any of their data. The stride of a dimension is the distance in storage units (pointers, small integers, floats, characters, whatever is in the array) between consecutive indexes along that dimension. Suppose you have a 3 x 3 matrix: 0 1 2 3 4 5 6 7 8 If it is stored row-by-row (C order) then it will appear in storage as 0 1 2 3 4 5 6 7 8. Suppose you are at location [0, 1], whose value is 1 (row indices are written before column indices). In order to get to [0, 2], the next column in the same row, you have to move along just 1 element. But to get to [1, 1], the next row in the same column, you have to move along 3 elements. So knowing the strides makes it easy to step along either rows or columns fast. But wait, there's more! Suppose you create a new array object, still 3 x 3, but with a row stride of 1 and a column stride of 3, but sharing the same storage. Hey presto, you now have transposed (rotated by 90 degrees) the original array, and it is now 0 3 6 1 4 7 2 5 8 In languages without strides, you'd have to copy all the elements. Here, no elements were copied in the making of this new array. As another example, say you create yet another array sharing the same storage. This one has one dimension only and a stride of 4. Its elements are 0 4 8 and in fact it is the diagonal of the (original or transposed) array. Again, no copying was done. By playing tricks with upper and lower bounds, strides, and the array offset (which is the storage address of point [0, 0]) you can translate a 0-based matrix to a 1-based matrix whose rows and columns are numbered 1, 2, 3 instead of 0, 1, 2, or even one with row and column numbers -1, 0, 1 if you want. You can get any of the corners of the array as 2 x 2 matrices. Everything generalizes to any number of dimensions, and there are many more possibilities: anything that can be expressed as an affine transformation can be obtained in this way. -- John Cowan http://vrici.lojban.org/~cowan cowan@ccil.org There are books that are at once excellent and boring. Those that at once leap to the mind are Thoreau's Walden, Emerson's Essays, George Eliot's Adam Bede, and Landor's Dialogues. --Somerset Maugham