nv-uintyped-mat

1.0.2 • Public • Published

nv-uintyped-mat

  • nv-uintyped-mat 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-mat

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

uint.buffer                uint.byteLength            uint.byteOffset
uint.copyWithin            uint.entries               uint.every
uint.fill                  uint.filter                uint.find
uint.findIndex             uint.forEach               uint.includes
uint.indexOf               uint.join                  uint.keys
uint.lastIndexOf           uint.length                uint.map
uint.reduce                uint.reduceRight           uint.reverse
uint.set                   uint.slice                 uint.some
uint.sort                  uint.subarray              uint.toLocaleString
uint.toString              uint.values

uint.BYTES_PER_ELEMENT     uint.constructor

uint.buf_size              uint.clear                 uint.clear_col
uint.clear_row             uint.cnget_indexes         uint.colnum
uint.empty                 uint.from_array            uint.from_col
uint.from_mat              uint.from_range            uint.from_row
uint.from_submat           uint.get_col               uint.get_mat
uint.get_row               uint.iclear_col            uint.iclear_row
uint.iget_cn               uint.iget_col              uint.iget_loc
uint.iget_range            uint.iget_rn               uint.iget_row
uint.iset_col              uint.iset_row              uint.loc_style
uint.locget                uint.locget_index          uint.locset
uint.real_size             uint.rnget_index           uint.rnget_range
uint.rownum                uint.set_col               uint.set_row
uint.set_submat            uint.shared                uint.submat
uint.swap_col              uint.swap_row              uint.swap_submat

LICENSE

  • ISC

Readme

Keywords

Package Sidebar

Install

npm i nv-uintyped-mat

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

20.9 kB

Total Files

3

Last publish

Collaborators

  • ihgazni2