Skip to content

Commit 0a8ef6c

Browse files
author
Symbolics
committed
Move map-array from num-utils
1 parent 6dbe6a6 commit 0a8ef6c

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

array-operations.asd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
;;; -*- Mode: LISP; Base: 10; Syntax: ANSI-Common-lisp; Package: ASDF -*-
22
;;; Copyright (c) 2012-2018 by Tamas Papp. All rights reserved.
33
;;; Copyright (c) 2019-2022 by Ben Dudson. All rights reserved.
4-
;;; Copyright (c) 2021-2022 by Symbolics Pte. Ltd. All rights reserved.
4+
;;; Copyright (c) 2021-2023 by Symbolics Pte. Ltd. All rights reserved.
55

66
(defsystem #:array-operations
7-
:version "1.0.0"
7+
:version "1.1.0"
88
:description "Array operations library for Common Lisp"
99
:long-description #.(uiop:read-file-string
1010
(uiop:subpathname *load-pathname* "description.text"))

docs/array-operations.epub

6 Bytes
Binary file not shown.

docs/array-operations.texi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@c Commentary:
1515

1616
@c Generated automatically by Declt version 4.0 beta 2 "William Riker"
17-
@c on Wed Jul 20 11:08:35 2022 GMT+8.
17+
@c on Wed Jul 20 11:53:52 2022 GMT+8.
1818

1919

2020
@c ====================================================================

src/transforming.lisp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;;; -*- Mode: LISP; Base: 10; Syntax: ANSI-Common-lisp; Package: ARRAY-OPERATIONS/TRANSFORMING -*-
22
;;; Copyright (c) 2012-2018 by Tamas Papp. All rights reserved.
33
;;; Copyright (c) 2018-2022 by Ben Dudson. All rights reserved.
4-
;;; Copyright (c) 2021-2022 by Symbolics Pte. Ltd. All rights reserved.
4+
;;; Copyright (c) 2021-2023 by Symbolics Pte. Ltd. All rights reserved.
55

66
(defpackage :array-operations/transforming
77
(:use :cl :array-operations/generic
@@ -27,6 +27,7 @@
2727
:permutation-incompatible-rank
2828
:permute
2929
:recycle
30+
:map-array
3031
:turn)
3132
(:documentation "Functions for transforming arrays in various ways."))
3233

@@ -344,8 +345,7 @@ Array element type is preserved."
344345
(deftype array-rank-element () `(integer 0 (,array-rank-limit)))
345346

346347
(defun turn (array nturns &optional (rank-1 0) (rank-2 1))
347-
"Turns an array by a specified number of clockwise 90° rotations. The axis of
348-
rotation is specified by RANK-1 (defaulting to 0) and RANK-2 (defaulting to 1)."
348+
"Turns an array by a specified number of clockwise 90° rotations. The axis of rotation is specified by RANK-1 (defaulting to 0) and RANK-2 (defaulting to 1)."
349349
(declare (optimize speed))
350350
(check-type array array)
351351
(check-type nturns integer)
@@ -393,3 +393,11 @@ rotation is specified by RANK-1 (defaulting to 0) and RANK-2 (defaulting to 1)."
393393
(locally (declare #+sbcl (sb-ext:muffle-conditions
394394
sb-ext:compiler-note))
395395
(row-major-aref array i)))))))
396+
397+
(defmethod map-array (array function
398+
&optional (retval (make-array (array-dimensions array))))
399+
"Apply FUNCTION to each element of ARRAY
400+
Return a new array, or write into the optional 3rd argument."
401+
(dotimes (i (array-total-size array) retval)
402+
(setf (row-major-aref retval i)
403+
(funcall function (row-major-aref array i)))))

tests/tests.lisp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;;; -*- Mode: LISP; Base: 10; Syntax: ANSI-Common-lisp; Package: ASDF -*-
22
;;; Copyright (c) 2012-2018 by Tamas Papp. All rights reserved.
33
;;; Copyright (c) 2018-2022 by Ben Dudson. All rights reserved.
4-
;;; Copyright (c) 2021-2022 by Symbolics Pte. Ltd. All rights reserved.
4+
;;; Copyright (c) 2021-2023 by Symbolics Pte. Ltd. All rights reserved.
55

66
(defpackage :array-operations/tests
77
(:use :cl :alexandria :clunit)
@@ -714,3 +714,8 @@
714714
#2A((0 1)
715715
(2 3))
716716
#2A((5) (9)))))
717+
718+
(deftest map-array (transformations)
719+
(let ((a #2A((1 2) (3 4))))
720+
(assert-equalp #2A((2 3) (4 5))
721+
(aops:map-array a #'1+))))

0 commit comments

Comments
 (0)