8
8
Supertype for `N`-dimensional arrays (or array-like types) with elements of type `T`.
9
9
[`Array`](@ref) and other types are subtypes of this. See the manual section on the
10
10
[`AbstractArray` interface](@ref man-interface-array).
11
+
12
+ See also: [`AbstractVector`](@ref), [`AbstractMatrix`](@ref), [`eltype`](@ref), [`ndims`](@ref).
11
13
"""
12
14
AbstractArray
13
15
@@ -24,6 +26,8 @@ dimension to just get the length of that dimension.
24
26
Note that `size` may not be defined for arrays with non-standard indices, in which case [`axes`](@ref)
25
27
may be useful. See the manual chapter on [arrays with custom indices](@ref man-custom-indices).
26
28
29
+ See also: [`length`](@ref), [`ndims`](@ref), [`eachindex`](@ref), [`sizeof`](@ref).
30
+
27
31
# Examples
28
32
```jldoctest
29
33
julia> A = fill(1, (2,3,4));
75
79
76
80
Return the tuple of valid indices for array `A`.
77
81
82
+ See also: [`size`](@ref), [`keys`](@ref), [`eachindex`](@ref).
83
+
78
84
# Examples
79
85
80
86
```jldoctest
@@ -174,6 +180,8 @@ For dictionary types, this will be a `Pair{KeyType,ValType}`. The definition
174
180
instead of types. However the form that accepts a type argument should be defined for new
175
181
types.
176
182
183
+ See also: [`keytype`](@ref), [`typeof`](@ref).
184
+
177
185
# Examples
178
186
```jldoctest
179
187
julia> eltype(fill(1f0, (2,2)))
@@ -202,6 +210,8 @@ elsize(A::AbstractArray) = elsize(typeof(A))
202
210
203
211
Return the number of dimensions of `A`.
204
212
213
+ See also: [`size`](@ref), [`axes`](@ref).
214
+
205
215
# Examples
206
216
```jldoctest
207
217
julia> A = fill(1, (3,4,5));
@@ -220,6 +230,8 @@ Return the number of elements in the collection.
220
230
221
231
Use [`lastindex`](@ref) to get the last valid index of an indexable collection.
222
232
233
+ See also: [`size`](@ref), [`ndims`](@ref), [`eachindex`](@ref).
234
+
223
235
# Examples
224
236
```jldoctest
225
237
julia> length(1:5)
@@ -336,6 +348,8 @@ Return the last index of `collection`. If `d` is given, return the last index of
336
348
The syntaxes `A[end]` and `A[end, end]` lower to `A[lastindex(A)]` and
337
349
`A[lastindex(A, 1), lastindex(A, 2)]`, respectively.
338
350
351
+ See also: [`axes`](@ref), [`firstindex`](@ref), [`eachindex`](@ref), [`prevind`](@ref).
352
+
339
353
# Examples
340
354
```jldoctest
341
355
julia> lastindex([1,2,4])
@@ -354,6 +368,11 @@ lastindex(a, d) = (@_inline_meta; last(axes(a, d)))
354
368
355
369
Return the first index of `collection`. If `d` is given, return the first index of `collection` along dimension `d`.
356
370
371
+ The syntaxes `A[begin]` and `A[1, begin]` lower to `A[firstindex(A)]` and
372
+ `A[1, firstindex(A, 2)]`, respectively.
373
+
374
+ See also: [`first`](@ref), [`axes`](@ref), [`lastindex`](@ref), [`nextind`](@ref).
375
+
357
376
# Examples
358
377
```jldoctest
359
378
julia> firstindex([1,2,4])
@@ -374,6 +393,8 @@ first(a::AbstractArray) = a[first(eachindex(a))]
374
393
Get the first element of an iterable collection. Return the start point of an
375
394
[`AbstractRange`](@ref) even if it is empty.
376
395
396
+ See also: [`only`](@ref), [`firstindex`](@ref), [`last`](@ref).
397
+
377
398
# Examples
378
399
```jldoctest
379
400
julia> first(2:2:10)
395
416
Get the first `n` elements of the iterable collection `itr`, or fewer elements if `itr` is not
396
417
long enough.
397
418
419
+ See also: [`startswith`](@ref), [`Iterators.take`](@ref).
420
+
398
421
!!! compat "Julia 1.6"
399
422
This method requires at least Julia 1.6.
400
423
@@ -426,6 +449,8 @@ Get the last element of an ordered collection, if it can be computed in O(1) tim
426
449
accomplished by calling [`lastindex`](@ref) to get the last index. Return the end
427
450
point of an [`AbstractRange`](@ref) even if it is empty.
428
451
452
+ See also [`first`](@ref), [`endswith`](@ref).
453
+
429
454
# Examples
430
455
```jldoctest
431
456
julia> last(1:2:10)
472
497
473
498
Return a tuple of the memory strides in each dimension.
474
499
500
+ See also: [`stride`](@ref).
501
+
475
502
# Examples
476
503
```jldoctest
477
504
julia> A = fill(1, (3,4,5));
@@ -487,6 +514,8 @@ function strides end
487
514
488
515
Return the distance in memory (in number of elements) between adjacent elements in dimension `k`.
489
516
517
+ See also: [`strides`](@ref).
518
+
490
519
# Examples
491
520
```jldoctest
492
521
julia> A = fill(1, (3,4,5));
@@ -660,6 +689,8 @@ Return `true` if the given `index` is within the bounds of
660
689
arrays can extend this method in order to provide a specialized bounds
661
690
checking implementation.
662
691
692
+ See also [`checkbounds`](@ref).
693
+
663
694
# Examples
664
695
```jldoctest
665
696
julia> checkindex(Bool, 1:20, 8)
@@ -735,6 +766,7 @@ julia> similar(falses(10), Float64, 2, 4)
735
766
2.18425e-314 2.18425e-314 2.18425e-314 2.18425e-314
736
767
```
737
768
769
+ See also: [`undef`](@ref), [`isassigned`](@ref).
738
770
"""
739
771
similar (a:: AbstractArray{T} ) where {T} = similar (a, T)
740
772
similar (a:: AbstractArray , :: Type{T} ) where {T} = similar (a, T, to_shape (axes (a)))
@@ -791,6 +823,8 @@ similar(::Type{T}, dims::Dims) where {T<:AbstractArray} = T(undef, dims)
791
823
792
824
Create an empty vector similar to `v`, optionally changing the `eltype`.
793
825
826
+ See also: [`empty!`](@ref), [`isempty`](@ref), [`isassigned`](@ref).
827
+
794
828
# Examples
795
829
796
830
```jldoctest
@@ -815,6 +849,7 @@ elements in `dst`.
815
849
If `dst` and `src` are of the same type, `dst == src` should hold after
816
850
the call. If `dst` and `src` are multidimensional arrays, they must have
817
851
equal [`axes`](@ref).
852
+
818
853
See also [`copyto!`](@ref).
819
854
820
855
!!! compat "Julia 1.1"
@@ -922,11 +957,12 @@ end
922
957
"""
923
958
copyto!(dest::AbstractArray, src) -> dest
924
959
925
-
926
960
Copy all elements from collection `src` to array `dest`, whose length must be greater than
927
961
or equal to the length `n` of `src`. The first `n` elements of `dest` are overwritten,
928
962
the other elements are left untouched.
929
963
964
+ See also [`copy!`](@ref Base.copy!), [`copy`](@ref).
965
+
930
966
# Examples
931
967
```jldoctest
932
968
julia> x = [1., 0., 3., 0., 5.];
@@ -2130,18 +2166,28 @@ end
2130
2166
foreach(f, c...) -> Nothing
2131
2167
2132
2168
Call function `f` on each element of iterable `c`.
2133
- For multiple iterable arguments, `f` is called elementwise.
2134
- `foreach` should be used instead of `map` when the results of `f` are not
2169
+ For multiple iterable arguments, `f` is called elementwise, and iteration stops when
2170
+ any iterator is finished.
2171
+
2172
+ `foreach` should be used instead of [`map`](@ref) when the results of `f` are not
2135
2173
needed, for example in `foreach(println, array)`.
2136
2174
2137
2175
# Examples
2138
2176
```jldoctest
2139
- julia> a = 1:3:7;
2177
+ julia> tri = 1:3:7; res = Int[] ;
2140
2178
2141
- julia> foreach(x -> println(x^2), a)
2142
- 1
2143
- 16
2144
- 49
2179
+ julia> foreach(x -> push!(res, x^2), tri)
2180
+
2181
+ julia> res
2182
+ 3-element Vector{$(Int) }:
2183
+ 1
2184
+ 16
2185
+ 49
2186
+
2187
+ julia> foreach((x, y) -> println(x, " with ", y), tri, 'a':'z')
2188
+ 1 with a
2189
+ 4 with b
2190
+ 7 with c
2145
2191
```
2146
2192
"""
2147
2193
foreach (f) = (f (); nothing )
@@ -2162,6 +2208,8 @@ colons go in this expression. The results are concatenated along the remaining d
2162
2208
For example, if `dims` is `[1,2]` and `A` is 4-dimensional, `f` is called on `A[:,:,i,j]`
2163
2209
for all `i` and `j`.
2164
2210
2211
+ See also [`eachcol`](@ref), [`eachslice`](@ref).
2212
+
2165
2213
# Examples
2166
2214
```jldoctest
2167
2215
julia> a = reshape(Vector(1:16),(2,2,2,2))
@@ -2308,9 +2356,9 @@ mapany(f, itr) = Any[f(x) for x in itr]
2308
2356
map(f, c...) -> collection
2309
2357
2310
2358
Transform collection `c` by applying `f` to each element. For multiple collection arguments,
2311
- apply `f` elementwise.
2359
+ apply `f` elementwise, and stop when when any of them is exhausted .
2312
2360
2313
- See also: [`mapslices`](@ref)
2361
+ See also: [`map!`](@ref), [`foreach`](@ref), [`mapreduce`](@ref), [` mapslices`](@ref), [`zip`](@ref), [`Iterators.map`](@ref).
2314
2362
2315
2363
# Examples
2316
2364
```jldoctest
@@ -2320,7 +2368,7 @@ julia> map(x -> x * 2, [1, 2, 3])
2320
2368
4
2321
2369
6
2322
2370
2323
- julia> map(+, [1, 2, 3], [10, 20, 30])
2371
+ julia> map(+, [1, 2, 3], [10, 20, 30, 400, 5000 ])
2324
2372
3-element Vector{Int64}:
2325
2373
11
2326
2374
22
@@ -2365,7 +2413,9 @@ end
2365
2413
map!(function, destination, collection...)
2366
2414
2367
2415
Like [`map`](@ref), but stores the result in `destination` rather than a new
2368
- collection. `destination` must be at least as large as the first collection.
2416
+ collection. `destination` must be at least as large as the smallest collection.
2417
+
2418
+ See also: [`map`](@ref), [`foreach`](@ref), [`zip`](@ref), [`copyto!`](@ref).
2369
2419
2370
2420
# Examples
2371
2421
```jldoctest
@@ -2378,6 +2428,14 @@ julia> a
2378
2428
2.0
2379
2429
4.0
2380
2430
6.0
2431
+
2432
+ julia> map!(+, zeros(Int, 5), 100:999, 1:3)
2433
+ 5-element Vector{$(Int) }:
2434
+ 101
2435
+ 103
2436
+ 105
2437
+ 0
2438
+ 0
2381
2439
```
2382
2440
"""
2383
2441
function map! (f:: F , dest:: AbstractArray , As:: AbstractArray... ) where {F}
0 commit comments