UNPKG

5.09 kBMarkdownView Raw
1<a name="Index"></a>
2## Index
3* [new Index(...ranges)](#new_Index_new)
4* _instance_
5 * [.valueOf](#Index+valueOf) ⇒ <code>Array</code>
6 * [.clone()](#Index+clone) ⇒ <code>[Index](#Index)</code>
7 * [.size()](#Index+size) ⇒ <code>Array.&lt;number&gt;</code>
8 * [.max()](#Index+max) ⇒ <code>Array.&lt;number&gt;</code>
9 * [.min()](#Index+min) ⇒ <code>Array.&lt;number&gt;</code>
10 * [.forEach(callback)](#Index+forEach)
11 * [.dimension(dim)](#Index+dimension) ⇒ <code>Range</code> &#124; <code>null</code>
12 * [.isScalar()](#Index+isScalar) ⇒ <code>boolean</code>
13 * [.toArray()](#Index+toArray) ⇒ <code>Array</code>
14 * [.toString()](#Index+toString) ⇒ <code>String</code>
15 * [.toJSON()](#Index+toJSON) ⇒ <code>Object</code>
16* _static_
17 * [.fromJSON(json)](#Index.fromJSON) ⇒ <code>[Index](#Index)</code>
18
19<a name="new_Index_new"></a>
20### new Index(...ranges)
21Create an index. An Index can store ranges and sets for multiple dimensions.
22Matrix.get, Matrix.set, and math.subset accept an Index as input.
23
24Usage:
25```js
26const index = new Index(range1, range2, matrix1, array1, ...)
27```
28
29Where each parameter can be any of:
30
31- A number
32- An instance of Range
33- An Array with the Set values
34- A Matrix with the Set values
35
36The parameters start, end, and step must be integer numbers.
37
38
39| Param | Type |
40| --- | --- |
41| ...ranges | <code>\*</code> |
42
43<a name="Index+valueOf"></a>
44### index.valueOf ⇒ <code>Array</code>
45Get the primitive value of the Index, a two dimensional array.
46Equivalent to Index.toArray().
47
48**Kind**: instance property of <code>[Index](#Index)</code>
49**Returns**: <code>Array</code> - array
50<a name="Index+clone"></a>
51### index.clone() ⇒ <code>[Index](#Index)</code>
52Create a clone of the index
53
54**Kind**: instance method of <code>[Index](#Index)</code>
55**Returns**: <code>[Index](#Index)</code> - clone
56<a name="Index+size"></a>
57### index.size() ⇒ <code>Array.&lt;number&gt;</code>
58Retrieve the size of the index, the number of elements for each dimension.
59
60**Kind**: instance method of <code>[Index](#Index)</code>
61**Returns**: <code>Array.&lt;number&gt;</code> - size
62<a name="Index+max"></a>
63### index.max() ⇒ <code>Array.&lt;number&gt;</code>
64Get the maximum value for each of the indexes ranges.
65
66**Kind**: instance method of <code>[Index](#Index)</code>
67**Returns**: <code>Array.&lt;number&gt;</code> - max
68<a name="Index+min"></a>
69### index.min() ⇒ <code>Array.&lt;number&gt;</code>
70Get the minimum value for each of the indexes ranges.
71
72**Kind**: instance method of <code>[Index](#Index)</code>
73**Returns**: <code>Array.&lt;number&gt;</code> - min
74<a name="Index+forEach"></a>
75### index.forEach(callback)
76Loop over each of the ranges of the index
77
78**Kind**: instance method of <code>[Index](#Index)</code>
79
80| Param | Type | Description |
81| --- | --- | --- |
82| callback | <code>function</code> | Called for each range with a Range as first argument, the dimension as second, and the index object as third. |
83
84<a name="Index+dimension"></a>
85### index.dimension(dim) ⇒ <code>Range</code> &#124; <code>null</code>
86Retrieve the dimension for the given index
87
88**Kind**: instance method of <code>[Index](#Index)</code>
89**Returns**: <code>Range</code> &#124; <code>null</code> - range
90
91| Param | Type | Description |
92| --- | --- | --- |
93| dim | <code>Number</code> | Number of the dimension |
94
95<a name="Index+isScalar"></a>
96### index.isScalar() ⇒ <code>boolean</code>
97Test whether this index contains only a single value.
98
99This is the case when the index is created with only scalar values as ranges,
100not for ranges resolving into a single value.
101
102**Kind**: instance method of <code>[Index](#Index)</code>
103**Returns**: <code>boolean</code> - isScalar
104<a name="Index+toArray"></a>
105### index.toArray() ⇒ <code>Array</code>
106Expand the Index into an array.
107For example new Index([0,3], [2,7]) returns [[0,1,2], [2,3,4,5,6]]
108
109**Kind**: instance method of <code>[Index](#Index)</code>
110**Returns**: <code>Array</code> - array
111<a name="Index+toString"></a>
112### index.toString() ⇒ <code>String</code>
113Get the string representation of the index, for example '[2:6]' or '[0:2:10, 4:7, [1,2,3]]'
114
115**Kind**: instance method of <code>[Index](#Index)</code>
116**Returns**: <code>String</code> - str
117<a name="Index+toJSON"></a>
118### index.toJSON() ⇒ <code>Object</code>
119Get a JSON representation of the Index
120
121**Kind**: instance method of <code>[Index](#Index)</code>
122**Returns**: <code>Object</code> - Returns a JSON object structured as:
123 `{"mathjs": "Index", "ranges": [{"mathjs": "Range", start: 0, end: 10, step:1}, ...]}`
124<a name="Index.fromJSON"></a>
125### Index.fromJSON(json) ⇒ <code>[Index](#Index)</code>
126Instantiate an Index from a JSON object
127
128**Kind**: static method of <code>[Index](#Index)</code>
129
130| Param | Type | Description |
131| --- | --- | --- |
132| json | <code>Object</code> | A JSON object structured as: `{"mathjs": "Index", "dimensions": [{"mathjs": "Range", start: 0, end: 10, step:1}, ...]}` |
133