@thi.ng/tensors 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +201 -0
- package/README.md +307 -0
- package/abs.d.ts +37 -0
- package/abs.js +14 -0
- package/add.d.ts +42 -0
- package/add.js +15 -0
- package/addn.d.ts +42 -0
- package/addn.js +15 -0
- package/api.d.ts +137 -0
- package/api.js +0 -0
- package/clamp.d.ts +47 -0
- package/clamp.js +15 -0
- package/clampn.d.ts +47 -0
- package/clampn.js +15 -0
- package/cos.d.ts +37 -0
- package/cos.js +14 -0
- package/defopn.d.ts +13 -0
- package/defopn.js +65 -0
- package/defoprt.d.ts +14 -0
- package/defoprt.js +77 -0
- package/defoprtt.d.ts +14 -0
- package/defoprtt.js +113 -0
- package/defopt.d.ts +13 -0
- package/defopt.js +109 -0
- package/defoptn.d.ts +13 -0
- package/defoptn.js +109 -0
- package/defoptnn.d.ts +13 -0
- package/defoptnn.js +109 -0
- package/defoptt.d.ts +13 -0
- package/defoptt.js +144 -0
- package/defopttt.d.ts +13 -0
- package/defopttt.js +177 -0
- package/div.d.ts +42 -0
- package/div.js +15 -0
- package/divn.d.ts +42 -0
- package/divn.js +15 -0
- package/dot.d.ts +31 -0
- package/dot.js +17 -0
- package/errors.d.ts +15 -0
- package/errors.js +9 -0
- package/exp.d.ts +37 -0
- package/exp.js +14 -0
- package/exp2.d.ts +37 -0
- package/exp2.js +14 -0
- package/format.d.ts +14 -0
- package/format.js +37 -0
- package/identity.d.ts +4 -0
- package/identity.js +11 -0
- package/index.d.ts +60 -0
- package/index.js +59 -0
- package/log.d.ts +37 -0
- package/log.js +14 -0
- package/log2.d.ts +37 -0
- package/log2.js +14 -0
- package/mag.d.ts +3 -0
- package/mag.js +5 -0
- package/magsq.d.ts +31 -0
- package/magsq.js +17 -0
- package/max.d.ts +37 -0
- package/max.js +14 -0
- package/maxn.d.ts +42 -0
- package/maxn.js +14 -0
- package/min.d.ts +37 -0
- package/min.js +14 -0
- package/minn.d.ts +42 -0
- package/minn.js +14 -0
- package/mul.d.ts +42 -0
- package/mul.js +15 -0
- package/mulm.d.ts +12 -0
- package/mulm.js +49 -0
- package/muln.d.ts +42 -0
- package/muln.js +15 -0
- package/mulv.d.ts +11 -0
- package/mulv.js +39 -0
- package/normalize.d.ts +3 -0
- package/normalize.js +11 -0
- package/package.json +261 -0
- package/pow.d.ts +37 -0
- package/pow.js +14 -0
- package/pown.d.ts +42 -0
- package/pown.js +14 -0
- package/product.d.ts +31 -0
- package/product.js +15 -0
- package/rand-distrib.d.ts +49 -0
- package/rand-distrib.js +52 -0
- package/relu.d.ts +37 -0
- package/relu.js +14 -0
- package/relun.d.ts +43 -0
- package/relun.js +14 -0
- package/select.d.ts +91 -0
- package/select.js +111 -0
- package/set.d.ts +8 -0
- package/set.js +14 -0
- package/setn.d.ts +8 -0
- package/setn.js +14 -0
- package/sigmoid.d.ts +39 -0
- package/sigmoid.js +15 -0
- package/sin.d.ts +37 -0
- package/sin.js +14 -0
- package/softmax.d.ts +27 -0
- package/softmax.js +10 -0
- package/softplus.d.ts +48 -0
- package/softplus.js +15 -0
- package/sqrt.d.ts +37 -0
- package/sqrt.js +14 -0
- package/step.d.ts +48 -0
- package/step.js +14 -0
- package/storage.d.ts +3 -0
- package/storage.js +32 -0
- package/sub.d.ts +42 -0
- package/sub.js +15 -0
- package/subn.d.ts +42 -0
- package/subn.js +15 -0
- package/sum.d.ts +31 -0
- package/sum.js +15 -0
- package/tan.d.ts +37 -0
- package/tan.js +14 -0
- package/tanh.d.ts +37 -0
- package/tanh.js +14 -0
- package/tensor.d.ts +127 -0
- package/tensor.js +517 -0
- package/top.d.ts +16 -0
- package/top.js +15 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
- **Last updated**: 2025-04-30T12:52:32Z
|
|
4
|
+
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
|
+
|
|
6
|
+
All notable changes to this project will be documented in this file.
|
|
7
|
+
Only versions published since **2022-01-01** are listed here.
|
|
8
|
+
Please consult the Git history for older version information.
|
|
9
|
+
See [Conventional Commits](https://conventionalcommits.org/) for commit guidelines.
|
|
10
|
+
|
|
11
|
+
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
|
+
and/or version bumps of transitive dependencies.
|
|
13
|
+
|
|
14
|
+
## [0.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/tensors@0.1.0) (2025-04-30)
|
|
15
|
+
|
|
16
|
+
#### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- initial import (old code, needs update) ([dc4f2b4](https://github.com/thi-ng/umbrella/commit/dc4f2b4))
|
|
19
|
+
- major updates & refactoring/cleanup ([49249a9](https://github.com/thi-ng/umbrella/commit/49249a9))
|
|
20
|
+
- update & restructure defOpXX() fns ([a96ecf8](https://github.com/thi-ng/umbrella/commit/a96ecf8))
|
|
21
|
+
- update TensorOpts and tensor factory fn, add docs ([21b8d48](https://github.com/thi-ng/umbrella/commit/21b8d48))
|
|
22
|
+
- update/replace tensor op generators, add op types ([2a00949](https://github.com/thi-ng/umbrella/commit/2a00949))
|
|
23
|
+
- add first set of common math ops ([00c02c1](https://github.com/thi-ng/umbrella/commit/00c02c1))
|
|
24
|
+
- add matrix-vector multiply, add custom error type ([a005276](https://github.com/thi-ng/umbrella/commit/a005276))
|
|
25
|
+
- add `identity()` factory fn ([1f2e914](https://github.com/thi-ng/umbrella/commit/1f2e914))
|
|
26
|
+
- add defOpRT(), add product/sum reducers ([19b6a9a](https://github.com/thi-ng/umbrella/commit/19b6a9a))
|
|
27
|
+
- add exp, log, softMax ops, update pkg exports ([465b0d2](https://github.com/thi-ng/umbrella/commit/465b0d2))
|
|
28
|
+
- add various math ops ([9e385ad](https://github.com/thi-ng/umbrella/commit/9e385ad))
|
|
29
|
+
- add/update various math ops, types, op factories ([a64468e](https://github.com/thi-ng/umbrella/commit/a64468e))
|
|
30
|
+
- add select(), argMin, argMax() fns ([fa508e1](https://github.com/thi-ng/umbrella/commit/fa508e1))
|
|
31
|
+
- add `print()` helper ([6c2e347](https://github.com/thi-ng/umbrella/commit/6c2e347))
|
|
32
|
+
- rename existing fn => `debug()`
|
|
33
|
+
- add softPlus() op ([1d85630](https://github.com/thi-ng/umbrella/commit/1d85630))
|
|
34
|
+
- add 4D tensor support & ops ([e3c9a0f](https://github.com/thi-ng/umbrella/commit/e3c9a0f))
|
|
35
|
+
- add exp2(), log2() ops ([18544a4](https://github.com/thi-ng/umbrella/commit/18544a4))
|
|
36
|
+
- update tensor(), add tensorFromArray(), add types/generics ([204734d](https://github.com/thi-ng/umbrella/commit/204734d))
|
|
37
|
+
|
|
38
|
+
#### 🩹 Bug fixes
|
|
39
|
+
|
|
40
|
+
- fix tensor scalar ops ([a26309d](https://github.com/thi-ng/umbrella/commit/a26309d))
|
|
41
|
+
|
|
42
|
+
#### ♻️ Refactoring
|
|
43
|
+
|
|
44
|
+
- minor update mulM() ([8bec8d1](https://github.com/thi-ng/umbrella/commit/8bec8d1))
|
|
45
|
+
- deduplicate tensor impls ([5fac485](https://github.com/thi-ng/umbrella/commit/5fac485))
|
|
46
|
+
- minor internal update arg types ([be56f5a](https://github.com/thi-ng/umbrella/commit/be56f5a))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
|
+
<!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
|
|
3
|
+
# 
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@thi.ng/tensors)
|
|
6
|
+

|
|
7
|
+
[](https://mastodon.thi.ng/@toxi)
|
|
8
|
+
|
|
9
|
+
> [!NOTE]
|
|
10
|
+
> This is one of 206 standalone projects, maintained as part
|
|
11
|
+
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
|
+
> and anti-framework.
|
|
13
|
+
>
|
|
14
|
+
> 🚀 Please help me to work full-time on these projects by [sponsoring me on
|
|
15
|
+
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
16
|
+
|
|
17
|
+
- [About](#about)
|
|
18
|
+
- [Built-in tensor operations](#built-in-tensor-operations)
|
|
19
|
+
- [Status](#status)
|
|
20
|
+
- [Installation](#installation)
|
|
21
|
+
- [Dependencies](#dependencies)
|
|
22
|
+
- [API](#api)
|
|
23
|
+
- [Basic usage](#basic-usage)
|
|
24
|
+
- [Matrix-matrix multiplication](#matrix-matrix-multiplication)
|
|
25
|
+
- [Matrix-vector multiplication](#matrix-vector-multiplication)
|
|
26
|
+
- [Authors](#authors)
|
|
27
|
+
- [License](#license)
|
|
28
|
+
|
|
29
|
+
## About
|
|
30
|
+
|
|
31
|
+
1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage.
|
|
32
|
+
|
|
33
|
+
> [!NOTE]
|
|
34
|
+
> This package contains code originally written in 2017/18 and, at the moment, is
|
|
35
|
+
> undergoing heavy refactoring to be stylistically more aligned with other thi.ng
|
|
36
|
+
> packages — use with caution!
|
|
37
|
+
|
|
38
|
+
## Built-in tensor operations
|
|
39
|
+
|
|
40
|
+
The set of tensor polymorphic component-wise ops is easily extensible via
|
|
41
|
+
provided higher-order functions in the `defOpXX()` family. Most of the ops
|
|
42
|
+
listed below are also based on this approach. The function signatures and naming
|
|
43
|
+
conventions are closely aligned to the ones used by the
|
|
44
|
+
[thi.ng/vectors](https://thi.ng/vectors) package.
|
|
45
|
+
|
|
46
|
+
- [abs](https://docs.thi.ng/umbrella/tensors/variables/abs.html)
|
|
47
|
+
- [add](https://docs.thi.ng/umbrella/tensors/variables/add.html)
|
|
48
|
+
- [addN](https://docs.thi.ng/umbrella/tensors/variables/addN.html)
|
|
49
|
+
- [argMax](https://docs.thi.ng/umbrella/tensors/variables/argMax.html)
|
|
50
|
+
- [argMin](https://docs.thi.ng/umbrella/tensors/variables/argMin.html)
|
|
51
|
+
- [clamp](https://docs.thi.ng/umbrella/tensors/variables/clamp.html)
|
|
52
|
+
- [clampN](https://docs.thi.ng/umbrella/tensors/variables/clampN.html)
|
|
53
|
+
- [cos](https://docs.thi.ng/umbrella/tensors/variables/cos.html)
|
|
54
|
+
- [div](https://docs.thi.ng/umbrella/tensors/variables/div.html)
|
|
55
|
+
- [divN](https://docs.thi.ng/umbrella/tensors/variables/divN.html)
|
|
56
|
+
- [dot](https://docs.thi.ng/umbrella/tensors/variables/dot.html)
|
|
57
|
+
- [exp](https://docs.thi.ng/umbrella/tensors/variables/exp.html)
|
|
58
|
+
- [exp2](https://docs.thi.ng/umbrella/tensors/variables/exp2.html)
|
|
59
|
+
- [log](https://docs.thi.ng/umbrella/tensors/variables/log.html)
|
|
60
|
+
- [log2](https://docs.thi.ng/umbrella/tensors/variables/log2.html)
|
|
61
|
+
- [mag](https://docs.thi.ng/umbrella/tensors/variables/mag.html)
|
|
62
|
+
- [magSq](https://docs.thi.ng/umbrella/tensors/variables/magSq.html)
|
|
63
|
+
- [max](https://docs.thi.ng/umbrella/tensors/variables/max.html)
|
|
64
|
+
- [maxN](https://docs.thi.ng/umbrella/tensors/variables/maxN.html)
|
|
65
|
+
- [min](https://docs.thi.ng/umbrella/tensors/variables/min.html)
|
|
66
|
+
- [minN](https://docs.thi.ng/umbrella/tensors/variables/minN.html)
|
|
67
|
+
- [mul](https://docs.thi.ng/umbrella/tensors/variables/mul.html)
|
|
68
|
+
- [mulN](https://docs.thi.ng/umbrella/tensors/variables/mulN.html)
|
|
69
|
+
- [mulM](https://docs.thi.ng/umbrella/tensors/variables/mulM.html): matrix-matrix product
|
|
70
|
+
- [mulV](https://docs.thi.ng/umbrella/tensors/variables/mulV.html): matrix-vector product
|
|
71
|
+
- [normalize](https://docs.thi.ng/umbrella/tensors/variables/normalize.html)
|
|
72
|
+
- [pow](https://docs.thi.ng/umbrella/tensors/variables/pow.html)
|
|
73
|
+
- [powN](https://docs.thi.ng/umbrella/tensors/variables/powN.html)
|
|
74
|
+
- [product](https://docs.thi.ng/umbrella/tensors/variables/product.html): component product
|
|
75
|
+
- [randDistrib](https://docs.thi.ng/umbrella/tensors/variables/randDistrib.html)
|
|
76
|
+
- [relu](https://docs.thi.ng/umbrella/tensors/variables/relu.html): ReLU activation
|
|
77
|
+
- [reluN](https://docs.thi.ng/umbrella/tensors/variables/reluN.html): leaky ReLU activation
|
|
78
|
+
- [select](https://docs.thi.ng/umbrella/tensors/variables/select.html): generalization of argMin/Max
|
|
79
|
+
- [set](https://docs.thi.ng/umbrella/tensors/variables/set.html): tensor setter
|
|
80
|
+
- [setN](https://docs.thi.ng/umbrella/tensors/variables/setN.html): tensor setter w/ uniform scalar
|
|
81
|
+
- [sigmoid](https://docs.thi.ng/umbrella/tensors/variables/sigmoid.html): Sigmoid activation
|
|
82
|
+
- [sin](https://docs.thi.ng/umbrella/tensors/variables/sin.html)
|
|
83
|
+
- [softMax](https://docs.thi.ng/umbrella/tensors/variables/softMax.html): Soft Max activation
|
|
84
|
+
- [sqrt](https://docs.thi.ng/umbrella/tensors/variables/sqrt.html)
|
|
85
|
+
- [step](https://docs.thi.ng/umbrella/tensors/variables/step.html): Threshold function (as as GLSL `step()`)
|
|
86
|
+
- [sub](https://docs.thi.ng/umbrella/tensors/variables/sub.html)
|
|
87
|
+
- [subN](https://docs.thi.ng/umbrella/tensors/variables/subN.html)
|
|
88
|
+
- [sum](https://docs.thi.ng/umbrella/tensors/variables/sum.html): component sum
|
|
89
|
+
- [tan](https://docs.thi.ng/umbrella/tensors/variables/tan.html)
|
|
90
|
+
- [tanh](https://docs.thi.ng/umbrella/tensors/variables/tanh.html)
|
|
91
|
+
|
|
92
|
+
## Status
|
|
93
|
+
|
|
94
|
+
**ALPHA** - bleeding edge / work-in-progress
|
|
95
|
+
|
|
96
|
+
[Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Btensors%5D+in%3Atitle)
|
|
97
|
+
|
|
98
|
+
## Installation
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
yarn add @thi.ng/tensors
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
ESM import:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import * as ten from "@thi.ng/tensors";
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Browser ESM import:
|
|
111
|
+
|
|
112
|
+
```html
|
|
113
|
+
<script type="module" src="https://esm.run/@thi.ng/tensors"></script>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
[JSDelivr documentation](https://www.jsdelivr.com/)
|
|
117
|
+
|
|
118
|
+
For Node.js REPL:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const ten = await import("@thi.ng/tensors");
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 7.07 KB
|
|
125
|
+
|
|
126
|
+
## Dependencies
|
|
127
|
+
|
|
128
|
+
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
129
|
+
- [@thi.ng/arrays](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays)
|
|
130
|
+
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
131
|
+
- [@thi.ng/equiv](https://github.com/thi-ng/umbrella/tree/develop/packages/equiv)
|
|
132
|
+
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
133
|
+
- [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
|
|
134
|
+
- [@thi.ng/random](https://github.com/thi-ng/umbrella/tree/develop/packages/random)
|
|
135
|
+
- [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
|
|
136
|
+
- [@thi.ng/vectors](https://github.com/thi-ng/umbrella/tree/develop/packages/vectors)
|
|
137
|
+
|
|
138
|
+
Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
|
|
139
|
+
|
|
140
|
+
## API
|
|
141
|
+
|
|
142
|
+
[Generated API docs](https://docs.thi.ng/umbrella/tensors/)
|
|
143
|
+
|
|
144
|
+
TODO
|
|
145
|
+
|
|
146
|
+
### Basic usage
|
|
147
|
+
|
|
148
|
+
```ts tangle:export/readme-1.ts
|
|
149
|
+
import * as t from "@thi.ng/tensors";
|
|
150
|
+
import { range } from "@thi.ng/transducers";
|
|
151
|
+
|
|
152
|
+
// create 4x4x4 3D tensor and fill with values
|
|
153
|
+
const a = t.tensor("f32", [4, 4, 4], { data: [...range(64)] });
|
|
154
|
+
|
|
155
|
+
t.print(a);
|
|
156
|
+
// --- 0: ---
|
|
157
|
+
// 0 1.0000 2.0000 3.0000
|
|
158
|
+
// 4.0000 5.0000 6.0000 7.0000
|
|
159
|
+
// 8.0000 9.0000 10.0000 11.0000
|
|
160
|
+
// 12.0000 13.0000 14.0000 15.0000
|
|
161
|
+
// --- 1: ---
|
|
162
|
+
// 16.0000 17.0000 18.0000 19.0000
|
|
163
|
+
// 20.0000 21.0000 22.0000 23.0000
|
|
164
|
+
// 24.0000 25.0000 26.0000 27.0000
|
|
165
|
+
// 28.0000 29.0000 30.0000 31.0000
|
|
166
|
+
// --- 2: ---
|
|
167
|
+
// 32.0000 33.0000 34.0000 35.0000
|
|
168
|
+
// 36.0000 37.0000 38.0000 39.0000
|
|
169
|
+
// 40.0000 41.0000 42.0000 43.0000
|
|
170
|
+
// 44.0000 45.0000 46.0000 47.0000
|
|
171
|
+
// --- 3: ---
|
|
172
|
+
// 48.0000 49.0000 50.0000 51.0000
|
|
173
|
+
// 52.0000 53.0000 54.0000 55.0000
|
|
174
|
+
// 56.0000 57.0000 58.0000 59.0000
|
|
175
|
+
// 60.0000 61.0000 62.0000 63.0000
|
|
176
|
+
|
|
177
|
+
// pick a tensor slice/axis (view only, 2d tensor)
|
|
178
|
+
t.print(a.pick([3]));
|
|
179
|
+
// 48.0000 49.0000 50.0000 51.0000
|
|
180
|
+
// 52.0000 53.0000 54.0000 55.0000
|
|
181
|
+
// 56.0000 57.0000 58.0000 59.0000
|
|
182
|
+
// 60.0000 61.0000 62.0000 63.0000
|
|
183
|
+
|
|
184
|
+
// any axis set to -1 will be skipped
|
|
185
|
+
// here we select slice 3 and column 2 only (1d tensor)
|
|
186
|
+
t.print(a.pick([3, -1, 2]));
|
|
187
|
+
// 50.0000 54.0000 58.0000 62.0000
|
|
188
|
+
|
|
189
|
+
// use `.pack()` to apply view to standalone densely packed tensor (own data)
|
|
190
|
+
console.log(a.pick([3, 2]).pack().data);
|
|
191
|
+
// Float32Array(4) [ 56, 57, 58, 59 ]
|
|
192
|
+
|
|
193
|
+
// only select every second value along each axis
|
|
194
|
+
t.print(a.step([2, 2, 2]));
|
|
195
|
+
// --- 0: ---
|
|
196
|
+
// 0 2.0000
|
|
197
|
+
// 8.0000 10.0000
|
|
198
|
+
// --- 1: ---
|
|
199
|
+
// 32.0000 34.0000
|
|
200
|
+
// 40.0000 42.0000
|
|
201
|
+
|
|
202
|
+
// extract an axis range (view only, use `.pack()` to extract)
|
|
203
|
+
t.print(a.lo([1, 1, 1]).hi([2, 2, 2]));
|
|
204
|
+
// --- 0: ---
|
|
205
|
+
// 21.0000 22.0000
|
|
206
|
+
// 25.0000 26.0000
|
|
207
|
+
// --- 1: ---
|
|
208
|
+
// 37.0000 38.0000
|
|
209
|
+
// 41.0000 42.0000
|
|
210
|
+
|
|
211
|
+
// read & write elements (no bounds checking!)
|
|
212
|
+
a.set([1, 2, 3], 100);
|
|
213
|
+
|
|
214
|
+
console.log(a.get([1, 2, 3]));
|
|
215
|
+
// 100
|
|
216
|
+
|
|
217
|
+
// or via direct array access
|
|
218
|
+
console.log(a.data[a.index([1, 2, 3])]);
|
|
219
|
+
// 100
|
|
220
|
+
|
|
221
|
+
// tensors are iterables (in current stride order)
|
|
222
|
+
console.log([...a]);
|
|
223
|
+
// [ 0, 1, 2, 3, 4, ... 60, 61, 62, 63 ]
|
|
224
|
+
|
|
225
|
+
// create a 2D tensor w/ random values (by default normal distribution, bias=0, std=1)
|
|
226
|
+
const b = t.randDistrib(t.tensor("f64", [4, 2]));
|
|
227
|
+
|
|
228
|
+
t.print(b);
|
|
229
|
+
// 0.3854 0.6597
|
|
230
|
+
// 0.5775 0.9201
|
|
231
|
+
// -0.7276 -0.1069
|
|
232
|
+
// 1.0550 0.4903
|
|
233
|
+
|
|
234
|
+
// apply sigmoid
|
|
235
|
+
// (null as output arg means mutate original [in 99% of all provided ops])
|
|
236
|
+
t.print(t.sigmoid(null, b));
|
|
237
|
+
// 0.5952 0.6592
|
|
238
|
+
// 0.6405 0.7151
|
|
239
|
+
// 0.3257 0.4733
|
|
240
|
+
// 0.7417 0.6202
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Matrix-matrix multiplication
|
|
244
|
+
|
|
245
|
+
```ts tangle:export/readme-mulm.ts
|
|
246
|
+
import { tensor, mulM, print } from "@thi.ng/tensors";
|
|
247
|
+
|
|
248
|
+
// create 2x3 matrix
|
|
249
|
+
const m1 = tensor([[1, 2, 3], [4, 5, 6]]);
|
|
250
|
+
|
|
251
|
+
print(m1);
|
|
252
|
+
// 1.0000 2.0000 3.0000
|
|
253
|
+
// 4.0000 5.0000 6.0000
|
|
254
|
+
|
|
255
|
+
// create transposed view (view only, zero-copy)
|
|
256
|
+
const m2 = m1.transpose([1, 0]);
|
|
257
|
+
|
|
258
|
+
print(m2);
|
|
259
|
+
// 1.0000 4.0000
|
|
260
|
+
// 2.0000 5.0000
|
|
261
|
+
// 3.0000 6.0000
|
|
262
|
+
|
|
263
|
+
// matrix multiplication
|
|
264
|
+
// (here if 1st arg is null, a new tensor will be created)
|
|
265
|
+
print(mulM(null, m1, m2));
|
|
266
|
+
// 14.0000 32.0000
|
|
267
|
+
// 32.0000 77.0000
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Matrix-vector multiplication
|
|
271
|
+
|
|
272
|
+
```ts tangle:export/readme-mulv.ts
|
|
273
|
+
import { tensor, mulV, print } from "@thi.ng/tensors";
|
|
274
|
+
|
|
275
|
+
// create 2x3 transformation matrix (row-major)
|
|
276
|
+
const mat = tensor([[10, 0, 100], [0, 5, 200]]);
|
|
277
|
+
|
|
278
|
+
print(mat);
|
|
279
|
+
// 10.0000 0 100.0000
|
|
280
|
+
// 0 5.0000 200.0000
|
|
281
|
+
|
|
282
|
+
// create vector
|
|
283
|
+
const vec = tensor([1, 1, 1]);
|
|
284
|
+
|
|
285
|
+
// matrix-vector multiply
|
|
286
|
+
print(mulV(null, mat, vec));
|
|
287
|
+
// 110.0000 205.0000
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Authors
|
|
291
|
+
|
|
292
|
+
- [Karsten Schmidt](https://thi.ng)
|
|
293
|
+
|
|
294
|
+
If this project contributes to an academic publication, please cite it as:
|
|
295
|
+
|
|
296
|
+
```bibtex
|
|
297
|
+
@misc{thing-tensors,
|
|
298
|
+
title = "@thi.ng/tensors",
|
|
299
|
+
author = "Karsten Schmidt",
|
|
300
|
+
note = "https://thi.ng/tensors",
|
|
301
|
+
year = 2018
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## License
|
|
306
|
+
|
|
307
|
+
© 2018 - 2025 Karsten Schmidt // Apache License 2.0
|
package/abs.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.abs` of given nD tensor and writes result to
|
|
3
|
+
* `out`. If `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
*/
|
|
8
|
+
export declare const abs: import("./api.js").MultiTensorOpT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link abs} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const abs1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link abs} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const abs2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link abs} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const abs3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link abs} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const abs4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=abs.d.ts.map
|
package/abs.js
ADDED
package/add.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise nD tensor addition. Writes result to `out`. If `out` is null,
|
|
3
|
+
* mutates `a`. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
* @param n - scalar
|
|
8
|
+
*/
|
|
9
|
+
export declare const add: import("./api.js").MultiTensorOpTT<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link add} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const add1: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link add} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const add2: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link add} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const add3: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link add} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const add4: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=add.d.ts.map
|
package/add.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $add } from "@thi.ng/vectors/ops";
|
|
2
|
+
import { defOpTT } from "./defoptt.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTT($add);
|
|
4
|
+
const add = a;
|
|
5
|
+
const add1 = b;
|
|
6
|
+
const add2 = c;
|
|
7
|
+
const add3 = d;
|
|
8
|
+
const add4 = e;
|
|
9
|
+
export {
|
|
10
|
+
add,
|
|
11
|
+
add1,
|
|
12
|
+
add2,
|
|
13
|
+
add3,
|
|
14
|
+
add4
|
|
15
|
+
};
|