Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d6098f

Browse files
committed
doc
1 parentb53f80f commit6d6098f

19 files changed

+1898
-2048
lines changed

‎docs/compute-engine/08-guide-types.md‎

Lines changed: 216 additions & 91 deletions
Large diffs are not rendered by default.

‎docs/compute-engine/82-reference-collections.md‎

Lines changed: 210 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,162 @@ into one unit. Each element in a collection is a
1212

1313
##Introduction
1414

15-
Collections are**immutable**. They cannot be modified. Operations on
16-
collections produce new collections.
15+
Collections are**immutable**: they cannot be modified in place.
16+
Operations oncollections produce new collections.
1717

18-
There are several types of collections in the Compute Engine:
19-
-**Lists**: ordered collections of elements, which are also used to represent
20-
**vectors** and**matrices**. Elements in a list are accessed by their
21-
index, which starts at 1.
22-
-**Sets**: unordered collections of unique elements. The elements in a set are
23-
not accessed by index, they are enumerated. A set can contain an infinite number
24-
of elements.
25-
-**Tuples**: ordered collections of elements, but with a fixed number of elements that have a specific type and an optional name.
26-
-**Records**: unordered collections of key-value pairs.
27-
-**Ranges** and**Linear Spaces (linspaces)**: ordered sequences of numbers (integers and reals, respectively) with a specified start, end and step size.
18+
The most common collection types are:
19+
-[**List**](#list): ordered collection of elements (duplicates allowed)
20+
-[**Set**](#set): unordered collection of unique elements
21+
-[**Tuple**](#tuple): ordered, fixed-size collection with optional names
22+
-[**Dictionary**](#dictionary): unordered key-value pairs with string keys
23+
-[**Record**](#record): structured data with a fixed set of known string keys
2824

25+
You can use collections to represent mathematical vectors, matrices, sequences, mappings, or records — in both finite and infinite forms.
2926

3027
<ReadMorepath="/compute-engine/reference/linear-algebra/" >
31-
See also the**Linear Algebra** section for operations on vectors, matrices andtensors.<Iconname="chevron-right-bold" />
28+
See also the**Linear Algebra** section for operations on vectors, matrices,tensors which are a special kind of collection.<Iconname="chevron-right-bold" />
3229
</ReadMore>
3330

3431

35-
###Operations on Collections
3632

37-
Operations creating new collections:
38-
-[**List**](#list),[**Range**](#range),[**Linspace**](#linspace),[**Set**](#set): create a new collection from some values.
39-
-[**Fill**](#fill),[**Repeat**](#repeat),[**Cycle**](#cycle),[**Iterate**](#iterate): create a new collection from a function or a value.
33+
###Core Properties of Collections
34+
35+
All collections share these basic properties:
36+
- Their elements can be**enumerated**
37+
- They can check whether an element is a**member** of the collection
38+
- The number of elements can be**counted**
39+
40+
**Note:** Depending on the type of collection, counting and membership checking can be an expensive operation, for example, for lazy infinite collections.
41+
42+
43+
###Finite and Infinite Collections
44+
45+
Collections may be:
46+
-**Finite**: containing a definite number of elements.
47+
-**Infinite**: continuing indefinitely (for example, a sequence of all natural numbers).
48+
49+
Compute Engine supports**lazy evaluation** to make working with infinite collections possible.
50+
51+
52+
###Lazy and Strict Collections
53+
54+
Collections can be:
55+
-**Strict**: elements are fully evaluated when the collection is created.
56+
-**Lazy**: elements are evaluated only as they are accessed.
57+
58+
Lazy collections are useful when working with infinite sequences or with expensive computations.
59+
60+
You can convert a lazy collection to a strict collection using`ListFrom` or`SetFrom`.
61+
These functions enumerate all elements (if finite) and produce a strict result.
62+
63+
```json example
64+
["ListFrom", ["Range",1,10]]
65+
// ➔ ["List", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
66+
```
67+
68+
###Why Lazy Infinite Collections?
69+
70+
Lazy infinite collections provide a natural way to model mathematical sequences, iterative processes, or cyclic patterns — with minimal memory use.
71+
Common examples include:
72+
- Natural numbers (`Range`)
73+
- Cyclic patterns (`Cycle`)
74+
- Iterative computations (`Iterate`)
75+
76+
77+
###Ordered and Unordered Collections
78+
79+
Collections fall into two broad categories:
80+
-**Ordered collections** (such as`List` and`Tuple`)
81+
→ Elements can be accessed by an**index**.
82+
The first element has index`1`, the second has index`2`, etc.
83+
Negative indexes count from the end: index`-1` is the last element.
84+
-**Unordered collections** (such as`Set`,`Record`)
85+
→ Elements cannot be accessed by index. They can be enumerated or looked up by key.
86+
87+
88+
###Types
89+
90+
- The type`collection` represents any collection, whether ordered or unordered, finite or infinite.
91+
- The type`ordered collection` applies to collections that support index-based access (such as`List`, and`Tuple`).
92+
93+
94+
95+
###Summary of Collection Types
96+
97+
| Collection Type| Ordered?| Unique Elements?| Fixed Size?| Lazy Possible?| Example|
98+
| ---------------| --------| ----------------| -----------| --------------| -------|
99+
|**List**| Yes| No| No| Yes|`["List", 1, 2, 3]`|
100+
|**Set**| No| Yes| No| Yes|`["Set", 1, 2, 3]`|
101+
|**Tuple**| Yes| No| Yes| No|`["Tuple", "x", "y"]`|
102+
|**Dictionary**| Keys unordered| Keys unique| No| No|`["Dictionary", ["Tuple", "a", 1], ["Tuple", "b", 2]]`|
103+
|**Record**| Keys unordered| Keys unique| Yes| No|`["Record", ["Tuple", "name", "Alice"], ["Tuple", "age", 30]]`|
104+
105+
*Note:*
106+
Collections like`Range`,`Cycle`,`Iterate`,`Repeat` create**lazy collections** that behave like infinite Lists, unless a strict conversion or truncation (e.g. with`Take()`) is used.
107+
108+
---
109+
110+
111+
###Ordered Collections
112+
113+
The elements of some collections can be accessed by their**index**, a
114+
number that indicates the position of the element in the collection.
115+
116+
Collections that can be accessed by index are called**ordered collections**.
117+
118+
The first element has index`1`, the second element has index`2`, and so on. The last
119+
element has index equal to the length of the collection.
120+
121+
Negative indexes can also be used to access elements from the end of the
122+
collection.
123+
124+
The last element has index`-1`, the second to last element has index`-2`,
125+
and so on. This is useful for accessing elements without knowing the length of the
126+
collection.
127+
128+
```json example
129+
["At", ["List",2,5,7,11],3]
130+
// ➔ 7
131+
132+
["At", ["List",2,5,7,11],-3]
133+
// ➔ 5
134+
```
135+
136+
137+
138+
Some of the collections in the Compute Engine include:
139+
-[**List**](#list): ordered collections of elements, which are also used to represent
140+
**vectors** and**matrices**. Elements in a list are accessed by their
141+
index, which starts at 1. Type:`list<T>` where`T` is the type of the elements.
142+
-[**Set**](#set): unordered collections of unique elements. The elements in a set are
143+
not accessed by index, they are enumerated. A set can contain an infinite number
144+
of elements. Type :`set<T>` where`T` is the type of the elements.
145+
-[**Tuple**](#tuple): ordered collections of elements, but with a fixed number
146+
of elements that have a specific type and an optional name. Type :`tuple<T1, T2, ..., Tn>` where`T1`,`T2`, ...,`Tn` are the types of the elements.
147+
-[**Dictionary**](#dictionary): unordered collections of key-value pairs,
148+
where each key is unique. Type:`dictionary<V>` where`V` is the type of the values, the keys are strings.
149+
-[**Record**](#record): unordered collections of key-value pairs. Unlike dictionaries, records are used to represent structured data with a fixed set of keys, and the keys are known at compile time.
150+
Type:`record<K1: T1, K2: T2, ..., Kn: Tn>` where`K1`,`K2`, ...,`Kn` are the keys and`T1`,`T2`, ...,`Tn` are the types of the values.
151+
152+
Some functions evaluate to a lazy collection. This is useful for creating
153+
infinite collections or for collections that are expensive to compute. Examples of lazy collections include:
154+
155+
-[**Range**](#range) and[**Linspace**](#linspace): ordered sequences of numbers (integers and reals, respectively) with a specified start, end and step size.
156+
-[**Cycle**](#cycle): infinite collections that repeat a finite collection.
157+
-[**Iterate**](#iterate): infinite collections that apply a function to an initial value repeatedly.
158+
-[**Repeat**](#repeat): infinite collections that repeat a single value.
159+
-[**Fill**](#fill): collections of a specified size, where each element is computed by a function or set to a specific value.
160+
161+
The type`collection` is used to represent any collection, whether it is ordered or unordered, finite or infinite.
162+
The type`ordered collection` is used to represent collections that can be accessed by index, such as`List`,`Tuple`, and`Dictionary`.
163+
164+
165+
166+
###Operations on Collections
40167

41168
Operations on ordered and unordered collections:
42-
-[**Length**](#length),[**IsEmpty**](#isempty): check the size of a collection.
169+
-[**Filter**](#filter),[**Map**](#map), and[**Reduce**](#reduce): operations that create new collections by applying a function to each element of an existing collection.
170+
-[**Length**](#length),[**IsEmpty**](#isempty): check the number of elements of a collection.
43171
-[**Filter**](#filter),[**Map**](#map),[**Reduce**](#reduce): apply a function to each element of a collection.
44172
-[**Join**](#join),[**Zip**](#zip): combine multiple collections into one.
45173
-[**Tally**](#tally): count the number of occurrences of each element in a collection.
@@ -54,26 +182,16 @@ Operations on ordered collections:
54182
-[**Unique**](#unique): remove duplicates from a collection.
55183
-[**RotateLeft**](#rotateleft),[**RotateRight**](#rotateright): rotate a collection to the left or right.
56184

185+
<ReadMorepath="/compute-engine/reference/linear-algebra/" >
186+
See also the**Linear Algebra** section for operations on vectors, matrices, tensors which are a special kind of collection.<Iconname="chevron-right-bold" />
187+
</ReadMore>
57188

58-
###Indexing Collections
59-
60-
Ordered collections (lists, tuples, ranges and linspaces) are indexed starting from 1. Negative indexes count from the end of
61-
the collection. For example,`-1` is the last element,`-2` is the second to last
62-
element, etc.
63-
64-
```json example
65-
["At", ["List",2,5,7,11],-2]
66-
// ➔ 7
67-
68-
["At", ["Range",2,10],-1]
69-
// ➔ ["List", 10]
70-
```
71189

72190

73191

74192
##Creating Collections
75193

76-
This section contains functions that create new collections from somevalues.
194+
This section contains functions that create new collections from someelements.
77195

78196
<divstyle={{visibility:"hidden"}}>
79197
###List
@@ -83,7 +201,7 @@ This section contains functions that create new collections from some values.
83201

84202
<Signaturename="List"returns="list">..._element_:any</Signature>
85203

86-
A`List` is an**ordered**,**indexable** collection of elements. An element in
204+
A`List` is an**ordered** collection of elements. An element in
87205
a list may be repeated.
88206

89207
<Latexvalue="\lbrack 42, 3.14, x, y \rbrack"/>
@@ -146,6 +264,65 @@ See also the **Linear Algebra** section for operations on vectors, matrices and
146264
</FunctionDefinition>
147265

148266

267+
<divstyle={{visibility:"hidden"}}>
268+
###Set
269+
</div>
270+
271+
<FunctionDefinitionname="Set">
272+
273+
<Signaturename="Set"returns="set">..._elements_:any</Signature>
274+
275+
An**unordered** collection of unique elements.
276+
277+
<Latexvalue="\lbrace 12, 15, 17 \rbrace"/>
278+
279+
```json example
280+
["Set",12,15,17]
281+
```
282+
283+
</FunctionDefinition>
284+
285+
<divstyle={{visibility:"hidden"}}>
286+
###Fill
287+
</div>
288+
289+
<FunctionDefinitionname="Fill">
290+
291+
<Signaturename="Fill"returns="list">_dimensions_,_value_:any</Signature>
292+
293+
<Signaturename="Fill"returns="list">_dimensions_,_f_:function</Signature>
294+
295+
Create a list of the specified dimensions.
296+
297+
If a`value` is provided, the elements of the list are all set to that value.
298+
299+
If a`function` is provided, the elements of the list are computed by applying
300+
the function to the index of the element.
301+
302+
If`dimensions` is a number, a list of that length is created.
303+
304+
```json example
305+
["Fill",3,0]
306+
// ➔ ["List", 0, 0, 0]
307+
```
308+
309+
If dimension is a tuple, a matrix of the specified dimensions is created.
310+
311+
```json example
312+
["Fill", ["Tuple",2,3],0]
313+
// ➔ ["List", ["List", 0, 0, 0], ["List", 0, 0, 0]]
314+
```
315+
316+
If a`function` is specified, it is applied to the index of the element to
317+
compute the value of the element.
318+
319+
```json example
320+
["Fill", ["Tuple",2,3], ["Function", ["Add","i","j"],"i","j"]]
321+
// ➔ ["List", ["List", 0, 1, 2], ["List", 1, 2, 3]]
322+
```
323+
324+
</FunctionDefinition>
325+
149326
<divstyle={{visibility:"hidden"}}>
150327
###Range
151328
</div>
@@ -248,64 +425,7 @@ If there is a single argument, it is assumed to be the `upper` bound, and the `l
248425
</FunctionDefinition>
249426

250427

251-
<divstyle={{visibility:"hidden"}}>
252-
###Set
253-
</div>
254-
255-
<FunctionDefinitionname="Set">
256-
257-
<Signaturename="Set"returns="set">..._elements_:any</Signature>
258428

259-
An**unordered** collection of unique elements.
260-
261-
<Latexvalue="\lbrace 12, 15, 17 \rbrace"/>
262-
263-
```json example
264-
["Set",12,15,17]
265-
```
266-
267-
</FunctionDefinition>
268-
269-
<divstyle={{visibility:"hidden"}}>
270-
###Fill
271-
</div>
272-
273-
<FunctionDefinitionname="Fill">
274-
275-
<Signaturename="Fill"returns="list">_dimensions_,_value_:any</Signature>
276-
277-
<Signaturename="Fill"returns="list">_dimensions_,_f_:function</Signature>
278-
279-
Create a list of the specified dimensions.
280-
281-
If a`value` is provided, the elements of the list are all set to that value.
282-
283-
If a`function` is provided, the elements of the list are computed by applying
284-
the function to the index of the element.
285-
286-
If`dimensions` is a number, a list of that length is created.
287-
288-
```json example
289-
["Fill",3,0]
290-
// ➔ ["List", 0, 0, 0]
291-
```
292-
293-
If dimension is a tuple, a matrix of the specified dimensions is created.
294-
295-
```json example
296-
["Fill", ["Tuple",2,3],0]
297-
// ➔ ["List", ["List", 0, 0, 0], ["List", 0, 0, 0]]
298-
```
299-
300-
If a`function` is specified, it is applied to the index of the element to
301-
compute the value of the element.
302-
303-
```json example
304-
["Fill", ["Tuple",2,3], ["Function", ["Add","i","j"],"i","j"]]
305-
// ➔ ["List", ["List", 0, 1, 2], ["List", 1, 2, 3]]
306-
```
307-
308-
</FunctionDefinition>
309429

310430
<divstyle={{visibility:"hidden"}}>
311431
###Repeat

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp