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