Skip to content

Add functions relating to multidimensional array indexing conversions

Anish Moorthy requested to merge anlsh/alexandria:indexing-helpers into master

Similar functions are provided in CL, but they operate on arrays when all they really need are the dimensions. This sometimes proves an annoyance, and I thought I'd submit the more general functions here. The behavior should exactly mimic that of the CL counterparts, except that the error which array-in-bounds-p signals is implementation-dependent and dim-in-bounds-p always signals a SIMPLE-ERROR.

This PR implements associated tests as well.

EDIT: I have also implemented a function to convert a row-major index to axis indices based on a given set of dimensions, and have implemented a test for that as well


I wanted to further propose extending these functions to cases when fewer indices than the rank of the array are given, ie something like

(defvar a #2A((a b c) (d e f))
(row-major-index (array-dimensions a) 0 0)     ;; 0
(row-major-index (array-dimensions a) 0)       ;; 0 . Currently an error
(row-major-index (array-dimensions a) 1)       ;; 3 . Also currently an error

(dim-in-bounds-p '(4 3 2 1) 0)                 ;; t . Currently an error

This behavior (unimplemented, to be clear) diverges more from the spec, but I often find it useful when working with multi-dimensional arrays. I can update the PR if we decide to support it.

Edited by Anish Moorthy

Merge request reports

Loading