Skip to content

Commit 935f0e5

Browse files
author
Symbolics
committed
The functions zeros and ones now accept T as an element type
Previously the array element type could only be T if you did not supply an element type optional parameter. This meant that the array type had to be known at compile time. With this change we can now specify all acceptable array types at run time.
1 parent 027a2dc commit 935f0e5

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

array-operations.asd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
;;; SPDX-License-identifier: MS-PL
66

77
(defsystem "array-operations"
8-
:version "1.2.0"
8+
:version "1.2.1"
99
:description "Array operations library for Common Lisp"
1010
:long-description #.(uiop:read-file-string
1111
(uiop:subpathname *load-pathname* "description.text"))

src/all.lisp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
;;; Copyright (c) 2012-2018 by Tamas Papp. All rights reserved.
33
;;; Copyright (c) 2018-2022 by Ben Dudson. All rights reserved.
44
;;; Copyright (c) 2021-2022 by Symbolics Pte. Ltd. All rights reserved.
5+
;;; SPDX-License-identifier: MS-PL
56

67
(uiop:define-package :array-operations/all
78
(:nicknames :array-operations :aops)

src/creating.lisp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ Returns ARRAY."
4242

4343
(defun zeros (dimensions &optional element-type)
4444
"Make an array of shape DIMENSIONS filled with zeros. Elements are of type T, unless ELEMENT-TYPE is given."
45-
(assert (subtypep element-type 'number)
45+
(assert (or (eq element-type t)
46+
(subtypep element-type 'number))
4647
(element-type)
4748
"Cannot create a ZEROS array because ~A is not a numeric type." element-type)
4849
(if element-type
@@ -62,7 +63,8 @@ Returns ARRAY."
6263

6364
(defun ones (dimensions &optional element-type)
6465
"Makes an array of shape DIMENSIONS filled with ones. Elements are of type T, unless ELEMENT-TYPE is given."
65-
(assert (subtypep element-type 'number)
66+
(assert (or (eq element-type t)
67+
(subtypep element-type 'number))
6668
(element-type)
6769
"Cannot create a ONES array because ~A is not a numeric type." element-type)
6870
(if element-type

src/matrices.lisp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
;;; Copyright (c) 2012-2018 by Tamas Papp. All rights reserved.
33
;;; Copyright (c) 2018-2022 by Ben Dudson. All rights reserved.
44
;;; Copyright (c) 2021-2022 by Symbolics Pte. Ltd. All rights reserved.
5+
;;; SPDX-License-identifier: MS-PL
56

6-
(defpackage :array-operations/matrices
7+
(uiop:define-package #:array-operations/matrices
78
(:use :cl :array-operations/generic)
8-
(:import-from :alexandria
9-
:length=)
10-
(:export :array-matrix
11-
:matrixp
12-
:square-matrix-p
9+
(:import-from #:alexandria #:length=)
10+
(:export #:array-matrix
11+
#:matrixp
12+
#:square-matrix-p
1313
;; the next two are deprecated aliases for the previous two
14-
:matrix?
15-
:square-matrix?)
14+
#:matrix?
15+
#:square-matrix?)
1616
(:documentation "Functions for representing matrices as 2D arrays. A matrix is a two-dimensional array often used for linear algebra. See also the matrix functions in NUM-UTILS, which should be migrated to AOPS."))
1717

18-
(in-package :array-operations/matrices)
18+
(in-package #:array-operations/matrices)
1919

2020
(deftype array-matrix ()
2121
"A rank-2 array."

tests/tests.lisp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
;;; Copyright (c) 2012-2018 by Tamas Papp. All rights reserved.
33
;;; Copyright (c) 2018-2022 by Ben Dudson. All rights reserved.
44
;;; Copyright (c) 2021-2023 by Symbolics Pte. Ltd. All rights reserved.
5+
;;; SPDX-License-identifier: MS-PL
56

6-
(defpackage :array-operations/tests
7+
(uiop:define-package #:array-operations/tests
78
(:use :cl :alexandria :clunit)
8-
(:export :run))
9+
(:export #:run))
910

10-
(cl:in-package :array-operations/tests)
11+
(in-package #:array-operations/tests)
1112

1213
(defsuite tests ())
1314
(defsuite creation (tests))
@@ -439,7 +440,6 @@
439440
(assert-equalp #(9 12 15)
440441
(aops:vectorize (a b) (+ a (* b 2))))))
441442

442-
443443
(deftest turn (transformations)
444444
(let ((array-1 #2A((1 0 0)
445445
(2 0 0)

0 commit comments

Comments
 (0)