Package Exports
- nv-uintyped-mat
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nv-uintyped-mat) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
nv-uintyped-array
- nv-uintyped-array creat a mat-view of Uint-TypedArray
- fixed col-number and row-number (when init)
- the buffer can be SharedArrayBuffer
install
- npm install nv-uintyped-array
usage
- creat\_uint\_mat(maxn,rownum,colnum=1,shared=true,empty=0,loc\_style=0)
- maxn is max-number/max-bigint permitted
- rownum is size
- if undefined, it will be calc from maxn,
- such as maxn = 9 (1001), size will be 16(10000)
- real\_size = colnum * rownum
- when colnum = 1(by default),its a series
- colnum >1 , its a mat
- buf\_size = Cls["BYTES\_PER\_ELEMENT"] * real\_size
- shared
- means if the bottom-buf is a sharedArrayBuffer
- empty
- means which number is used as empty,default is 0/0n
- used by clear
- loc\_style index for mat (colnum>1)
- 0: start from 0
- 1: start from 1
example
maxn and rownum
var uint = creat_uint_mat(13)
> uint
Uint8Array(16) [
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
]
>
> var uint = creat_uint_mat(255)
> uint
Uint8Array(256) [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
.....
0, 0, 0, 0,
... 156 more items
]
>
> var uint = creat_uint_mat(50000)
> uint
Uint16Array(65536) [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
............
0, 0, 0, 0,
... 65436 more items
]
>
> var uint = creat_uint_mat(2**32-1,20)
> uint
Uint32Array(20) [
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
]
>
shared-buffer (default true)
> var uint = creat_uint_mat(2**53,20)
> uint
BigUint64Array(20) [
0n, 0n, 0n, 0n, 0n, 0n, 0n,
0n, 0n, 0n, 0n, 0n, 0n, 0n,
0n, 0n, 0n, 0n, 0n, 0n
]
> uint.buffer
SharedArrayBuffer {
[Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 60 more bytes>,
byteLength: 160
}
>
mat
//4 rows * 9 cols
var uint = creat_uint_mat(65535,4,9)
> uint
Uint16Array(36) [
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0
]
> uint.colnum
9
>
> uint.rownum
4
> uint.real_size
36
> uint.buf_size
72
>
uint.set_row(2,999)
> uint
Uint16Array(36) [
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
999, 999, 999, 999, 999, 999, 999, 999, 999,
0, 0, 0, 0, 0, 0, 0, 0, 0
]
>
uint.set_col(2,888)
> uint
Uint16Array(36) [
0, 0, 888, 0, 0, 0, 0, 0, 0,
0, 0, 888, 0, 0, 0, 0, 0, 0,
999, 999, 888, 999, 999, 999, 999, 999, 999,
0, 0, 888, 0, 0, 0, 0, 0, 0
]
>
> var col = uint.get_col(2)
undefined
> col
[
Uint16Array(1) [ 888 ],
Uint16Array(1) [ 888 ],
Uint16Array(1) [ 888 ],
Uint16Array(1) [ 888 ]
]
>
col[1][0] = 777
> uint
Uint16Array(36) [
0, 0, 888, 0, 0, 0, 0, 0, 0,
0, 0, 777, 0, 0, 0, 0, 0, 0,
999, 999, 888, 999, 999, 999, 999, 999, 999,
0, 0, 888, 0, 0, 0, 0, 0, 0
]
>
> uint.locget(1,2)
777
>
uint.from_row(0,[1,2,3,4,5,6,7,8])
> uint
Uint16Array(36) [
1, 2, 3, 4, 5, 6, 7, 8, 0,
0, 0, 777, 0, 0, 0, 0, 0, 0,
999, 999, 888, 999, 999, 999, 999, 999, 999,
0, 0, 888, 0, 0, 0, 0, 0, 0
]
>
> uint.from_col(7,[10,10,10,10])
[
Uint16Array(1) [ 10 ],
Uint16Array(1) [ 10 ],
Uint16Array(1) [ 10 ],
Uint16Array(1) [ 10 ]
]
> uint
Uint16Array(36) [
1, 2, 3, 4, 5, 6, 7, 10, 0,
0, 0, 777, 0, 0, 0, 0, 10, 0,
999, 999, 888, 999, 999, 999, 999, 10, 999,
0, 0, 888, 0, 0, 0, 0, 10, 0
]
>
> uint.empty=65535
> uint.clear_row(2)
Uint16Array(9) [
65535, 65535,
65535, 65535,
65535, 65535,
65535, 65535,
65535
]
>
> uint
Uint16Array(36) [
1, 2, 3, 4, 5, 6,
7, 10, 0, 0, 0, 777,
0, 0, 0, 0, 10, 0,
65535, 65535, 65535, 65535, 65535, 65535,
65535, 65535, 65535, 0, 0, 888,
0, 0, 0, 0, 10, 0
]
>
swap
var uint = creat_uint_mat(65535,4,9)
uint.set_row(0,11)
uint.set_row(1,22)
uint.set_row(2,33)
uint.set_row(3,44)
> uint
Uint16Array(36) [
11, 11, 11, 11, 11, 11, 11, 11, 11,
22, 22, 22, 22, 22, 22, 22, 22, 22,
33, 33, 33, 33, 33, 33, 33, 33, 33,
44, 44, 44, 44, 44, 44, 44, 44, 44
]
>
uint.swap_row(0,2)
> uint
Uint16Array(36) [
33, 33, 33, 33, 33, 33, 33, 33, 33,
22, 22, 22, 22, 22, 22, 22, 22, 22,
11, 11, 11, 11, 11, 11, 11, 11, 11,
44, 44, 44, 44, 44, 44, 44, 44, 44
]
>
var uint = creat_uint_mat(65535,4,9)
uint.set_col(0,11)
uint.set_col(1,22)
uint.set_col(2,33)
uint.set_col(3,44)
> uint
Uint16Array(36) [
11, 22, 33, 44, 0, 0, 0, 0, 0,
11, 22, 33, 44, 0, 0, 0, 0, 0,
11, 22, 33, 44, 0, 0, 0, 0, 0,
11, 22, 33, 44, 0, 0, 0, 0, 0
]
>
> uint.swap_col(0,2)
> uint
Uint16Array(36) [
33, 22, 11, 44, 0, 0, 0, 0, 0,
33, 22, 11, 44, 0, 0, 0, 0, 0,
33, 22, 11, 44, 0, 0, 0, 0, 0,
33, 22, 11, 44, 0, 0, 0, 0, 0
]
>
submat
var uint = creat_uint_mat(65535,4,9)
uint.set_col(0,11)
uint.set_col(1,22)
uint.set_col(2,33)
uint.set_col(3,44)
var m = uint.get_mat()
[
[11, 22, 33, 44, 0,0, 0, 0, 0],
[11, 22, 33, 44, 0,0, 0, 0, 0],
[11, 22, 33, 44, 0,0, 0, 0, 0],
[11, 22, 33, 44, 0,0, 0, 0, 0],
]
>
var uint = creat_uint_mat(65535,4,9)
uint.from_mat(m)
> uint
Uint16Array(36) [
11, 22, 33, 44, 0, 0, 0, 0, 0,
11, 22, 33, 44, 0, 0, 0, 0, 0,
11, 22, 33, 44, 0, 0, 0, 0, 0,
11, 22, 33, 44, 0, 0, 0, 0, 0
]
>
var uint = creat_uint_mat(65535,4,9)
uint.from_range(1,37)
> uint
Uint16Array(36) [
0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35
]
>
> uint.submat([1,1],[3,4])
[
Uint16Array(4) [ 10, 11, 12, 13 ],
Uint16Array(4) [ 19, 20, 21, 22 ],
Uint16Array(4) [ 28, 29, 30, 31 ]
]
>
uint.submat([1,1],[3,4])[1][1] = 999
> uint
Uint16Array(36) [
0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 999, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35
]
>
uint.set_submat([1,1],[3,4],0)
> uint
Uint16Array(36) [
0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 0, 0, 0, 0, 14, 15, 16, 17,
18, 0, 0, 0, 0, 23, 24, 25, 26,
27, 0, 0, 0, 0, 32, 33, 34, 35
]
>
var sm = [
[400,500],
[600,700]
]
uint.from_submat([1,6],[2,7],sm)
> uint
Uint16Array(36) [
0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 0, 0, 0, 0, 14, 400, 500, 17,
18, 0, 0, 0, 0, 23, 600, 700, 26,
27, 0, 0, 0, 0, 32, 33, 34, 35
]
>
uint.swap_submat([1,6],[2,7],[2,1],[3,2])
> uint
Uint16Array(36) [
0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 0, 0, 0, 0, 14, 0, 0, 17,
18, 400, 500, 0, 0, 23, 0, 0, 26,
27, 600, 700, 0, 0, 32, 33, 34, 35
]
>
METHODS
LICENSE
- ISC