Skip to content

Commit 7645e92

Browse files
author
Symbolics
committed
Document new optional arguments to array generating functions
1 parent 3d72f14 commit 7645e92

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

content/en/docs/Manuals/array-operations.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,22 +251,18 @@ instead of the longer form
251251

252252
## Creation & transformation
253253

254-
When the resulting element type cannot be inferred, functions that
255-
create and transform arrays are provided in pairs; one of these will
256-
allow you to specify the array-element-type of the result, while the
257-
other assumes it is `t`. The former ends with a `*`, and the
258-
`element-type` is always its first argument. Examples are given for
259-
the versions without `*`; use the other when you are optimizing your
260-
code and you are sure you can constrain to a given element-type.
254+
Use the functions in this section to create commonly used arrays
255+
types. When the resulting element type cannot be inferred from an
256+
existing array or vector, you can pass the element type as an optional
257+
argument. The default is elements of type `T`.
261258

262259
*Element traversal order of these functions is unspecified*. The
263260
reason for this is that the library may use parallel code in the
264261
future, so it is unsafe to rely on a particular element traversal
265262
order.
266263

267264
The following functions all make a new array, taking the dimensions as
268-
input. The version ending in `*` also takes the array type as first
269-
argument. There are also versions ending in `!` which do not make a
265+
input. There are also versions ending in `!` which do not make a
270266
new array, but take an array as first argument, which is modified and
271267
returned.
272268

@@ -280,16 +276,23 @@ returned.
280276

281277
For example:
282278
```lisp
279+
(aops:zeros 3)
280+
; => #(0 0 0)
281+
282+
(aops:zeros 3 'double-float)
283+
; => #(0.0d0 0.0d0 0.0d0)
284+
283285
(aops:rand '(2 2))
284286
; => #2A((0.6686077 0.59425664)
285287
; (0.7987722 0.6930506))
286288
287-
(aops:rand* 'single-float '(2 2))
289+
(aops:rand '(2 2) 'single-float)
288290
; => #2A((0.39332366 0.5557821)
289291
; (0.48831415 0.10924244))
290292
291293
(let ((a (make-array '(2 2) :element-type 'double-float)))
292294
;; Modify array A, filling with random numbers
295+
;; element type is taken from existing array
293296
(aops:rand! a))
294297
; => #2A((0.6324615478515625d0 0.4636608362197876d0)
295298
; (0.4145939350128174d0 0.5124958753585815d0))
@@ -298,6 +301,7 @@ For example:
298301
```lisp
299302
(linspace 0 4 5) ;=> #(0 1 2 3 4)
300303
(linspace 1 3 5) ;=> #(0 1/2 1 3/2 2)
304+
(linspace 1 3 5 'double-float) ;=> #(1.0d0 1.5d0 2.0d0 2.5d0 3.0d0)
301305
(linspace 0 4d0 3) ;=> #(0.0d0 2.0d0 4.0d0)
302306
```
303307

0 commit comments

Comments
 (0)