1 | import { factory } from '../../utils/factory'
|
2 | import { clone } from '../../utils/object'
|
3 | import { validateIndex } from '../../utils/array'
|
4 |
|
5 | const name = 'row'
|
6 | const dependencies = ['typed', 'Index', 'matrix', 'range']
|
7 |
|
8 | export const createRow = factory(name, dependencies, ({ typed, Index, matrix, range }) => {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | return typed(name, {
|
31 | 'Matrix, number': _row,
|
32 |
|
33 | 'Array, number': function (value, row) {
|
34 | return _row(matrix(clone(value)), row).valueOf()
|
35 | }
|
36 | })
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | function _row (value, row) {
|
45 |
|
46 | if (value.size().length !== 2) {
|
47 | throw new Error('Only two dimensional matrix is supported')
|
48 | }
|
49 |
|
50 | validateIndex(row, value.size()[0])
|
51 |
|
52 | const columnRange = range(0, value.size()[1])
|
53 | const index = new Index(row, columnRange)
|
54 | return value.subset(index)
|
55 | }
|
56 | })
|