maten 0.1.0__tar.gz
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.
- maten-0.1.0/CHANGELOG.md +17 -0
- maten-0.1.0/LICENSE +21 -0
- maten-0.1.0/MANIFEST.in +6 -0
- maten-0.1.0/PKG-INFO +123 -0
- maten-0.1.0/README.md +73 -0
- maten-0.1.0/docs/core.md +28 -0
- maten-0.1.0/docs/frame.md +22 -0
- maten-0.1.0/docs/neural.md +35 -0
- maten-0.1.0/docs/plot.md +23 -0
- maten-0.1.0/maten/__init__.py +57 -0
- maten-0.1.0/maten/core/creation.py +68 -0
- maten-0.1.0/maten/core/linalg.py +78 -0
- maten-0.1.0/maten/core/math_ops.py +56 -0
- maten-0.1.0/maten/core/tensor.py +250 -0
- maten-0.1.0/maten/frame/__init__.py +15 -0
- maten-0.1.0/maten/frame/dataframe.py +287 -0
- maten-0.1.0/maten/frame/groupby.py +80 -0
- maten-0.1.0/maten/frame/io.py +50 -0
- maten-0.1.0/maten/frame/series.py +178 -0
- maten-0.1.0/maten/neural/__init__.py +32 -0
- maten-0.1.0/maten/neural/autograd.py +96 -0
- maten-0.1.0/maten/neural/dataloader.py +78 -0
- maten-0.1.0/maten/neural/layers.py +132 -0
- maten-0.1.0/maten/neural/losses.py +60 -0
- maten-0.1.0/maten/neural/metrics.py +47 -0
- maten-0.1.0/maten/neural/optimizers.py +114 -0
- maten-0.1.0/maten/neural/sequential.py +63 -0
- maten-0.1.0/maten/neural/tensor.py +157 -0
- maten-0.1.0/maten/plot/__init__.py +19 -0
- maten-0.1.0/maten/plot/charts.py +98 -0
- maten-0.1.0/maten/plot/colors.py +21 -0
- maten-0.1.0/maten/plot/figure.py +342 -0
- maten-0.1.0/maten/plot/utils.py +39 -0
- maten-0.1.0/maten.egg-info/PKG-INFO +123 -0
- maten-0.1.0/maten.egg-info/SOURCES.txt +43 -0
- maten-0.1.0/maten.egg-info/dependency_links.txt +1 -0
- maten-0.1.0/maten.egg-info/top_level.txt +1 -0
- maten-0.1.0/pyproject.toml +36 -0
- maten-0.1.0/setup.cfg +29 -0
- maten-0.1.0/setup.py +22 -0
- maten-0.1.0/tests/test_core.py +57 -0
- maten-0.1.0/tests/test_frame.py +71 -0
- maten-0.1.0/tests/test_neural.py +72 -0
- maten-0.1.0/tests/test_plot.py +28 -0
maten-0.1.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-06-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial release with four subpackages:
|
|
13
|
+
- `maten.core` — NumPy-like tensor operations
|
|
14
|
+
- `maten.frame` — Pandas-like Series and DataFrame
|
|
15
|
+
- `maten.plot` — Matplotlib-like plotting (SVG output)
|
|
16
|
+
- `maten.neural` — TensorFlow-like autograd and training utilities
|
|
17
|
+
- Unit tests, examples, and documentation
|
maten-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maten Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
maten-0.1.0/MANIFEST.in
ADDED
maten-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: maten
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pure Python scientific computing — replaces NumPy, Pandas, Matplotlib & TensorFlow
|
|
5
|
+
Home-page: https://github.com/maten/maten
|
|
6
|
+
Author: maten contributors
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Maten Contributors
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/yourname/maten
|
|
30
|
+
Project-URL: Issues, https://github.com/yourname/maten/issues
|
|
31
|
+
Keywords: numpy,pandas,matplotlib,tensorflow,machine-learning,dataframe,tensor,neural-network,pure-python,zero-dependency
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Topic :: Scientific/Engineering
|
|
43
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
44
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
45
|
+
Requires-Python: >=3.8
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
License-File: LICENSE
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
Dynamic: requires-python
|
|
50
|
+
|
|
51
|
+
# Maten
|
|
52
|
+
|
|
53
|
+
A lightweight, dependency-free Python toolkit that provides NumPy-, Pandas-, Matplotlib-, and TensorFlow-like APIs for learning and prototyping.
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- **maten.core** — N-dimensional tensors, element-wise math, and linear algebra
|
|
58
|
+
- **maten.frame** — Series, DataFrame, groupby, and CSV/JSON I/O
|
|
59
|
+
- **maten.plot** — SVG charts (line, bar, scatter, hist, pie, heatmap)
|
|
60
|
+
- **maten.neural** — Scalar autograd, layers, optimizers, and a simple trainer
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
From the project root:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install .
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Editable install for development:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install -e ".[dev]"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Quick start
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import maten
|
|
80
|
+
from maten.core import Tensor, zeros
|
|
81
|
+
from maten.frame import DataFrame
|
|
82
|
+
from maten.plot import subplots, line
|
|
83
|
+
from maten.neural import Value
|
|
84
|
+
|
|
85
|
+
print(maten.__version__)
|
|
86
|
+
print(zeros(3))
|
|
87
|
+
print(DataFrame({"x": [1, 2, 3]}))
|
|
88
|
+
|
|
89
|
+
_, ax = subplots()
|
|
90
|
+
line(ax, [0, 1, 2], [0, 1, 4])
|
|
91
|
+
ax.save("demo.svg")
|
|
92
|
+
|
|
93
|
+
x = Value(2.0)
|
|
94
|
+
y = x * x
|
|
95
|
+
y.backward()
|
|
96
|
+
print(x.grad) # 4.0
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Examples
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
python examples/core_demo.py
|
|
103
|
+
python examples/frame_demo.py
|
|
104
|
+
python examples/plot_demo.py
|
|
105
|
+
python examples/neural_demo.py
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Tests
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pytest
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Documentation
|
|
115
|
+
|
|
116
|
+
- [Core](docs/core.md)
|
|
117
|
+
- [Frame](docs/frame.md)
|
|
118
|
+
- [Plot](docs/plot.md)
|
|
119
|
+
- [Neural](docs/neural.md)
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT — see [LICENSE](LICENSE).
|
maten-0.1.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Maten
|
|
2
|
+
|
|
3
|
+
A lightweight, dependency-free Python toolkit that provides NumPy-, Pandas-, Matplotlib-, and TensorFlow-like APIs for learning and prototyping.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **maten.core** — N-dimensional tensors, element-wise math, and linear algebra
|
|
8
|
+
- **maten.frame** — Series, DataFrame, groupby, and CSV/JSON I/O
|
|
9
|
+
- **maten.plot** — SVG charts (line, bar, scatter, hist, pie, heatmap)
|
|
10
|
+
- **maten.neural** — Scalar autograd, layers, optimizers, and a simple trainer
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
From the project root:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install .
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Editable install for development:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install -e ".[dev]"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import maten
|
|
30
|
+
from maten.core import Tensor, zeros
|
|
31
|
+
from maten.frame import DataFrame
|
|
32
|
+
from maten.plot import subplots, line
|
|
33
|
+
from maten.neural import Value
|
|
34
|
+
|
|
35
|
+
print(maten.__version__)
|
|
36
|
+
print(zeros(3))
|
|
37
|
+
print(DataFrame({"x": [1, 2, 3]}))
|
|
38
|
+
|
|
39
|
+
_, ax = subplots()
|
|
40
|
+
line(ax, [0, 1, 2], [0, 1, 4])
|
|
41
|
+
ax.save("demo.svg")
|
|
42
|
+
|
|
43
|
+
x = Value(2.0)
|
|
44
|
+
y = x * x
|
|
45
|
+
y.backward()
|
|
46
|
+
print(x.grad) # 4.0
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Examples
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
python examples/core_demo.py
|
|
53
|
+
python examples/frame_demo.py
|
|
54
|
+
python examples/plot_demo.py
|
|
55
|
+
python examples/neural_demo.py
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Tests
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pytest
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Documentation
|
|
65
|
+
|
|
66
|
+
- [Core](docs/core.md)
|
|
67
|
+
- [Frame](docs/frame.md)
|
|
68
|
+
- [Plot](docs/plot.md)
|
|
69
|
+
- [Neural](docs/neural.md)
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT — see [LICENSE](LICENSE).
|
maten-0.1.0/docs/core.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# maten.core
|
|
2
|
+
|
|
3
|
+
NumPy-like tensor library with zero external dependencies.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from maten.core import Tensor, zeros, ones, arange, sin, matmul
|
|
9
|
+
|
|
10
|
+
x = Tensor([[1, 2], [3, 4]])
|
|
11
|
+
y = zeros((2, 2))
|
|
12
|
+
print(x + y)
|
|
13
|
+
print(matmul(x, x.T()))
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## API overview
|
|
17
|
+
|
|
18
|
+
| Module | Purpose |
|
|
19
|
+
|--------|---------|
|
|
20
|
+
| `tensor.py` | `Tensor` class — shape, indexing, arithmetic, reshape, transpose |
|
|
21
|
+
| `creation.py` | `zeros`, `ones`, `arange`, `linspace`, `eye` |
|
|
22
|
+
| `math_ops.py` | `sin`, `cos`, `exp`, `log`, `sqrt`, `relu` |
|
|
23
|
+
| `linalg.py` | `norm`, `trace`, `det`, `matmul` |
|
|
24
|
+
|
|
25
|
+
## Notes
|
|
26
|
+
|
|
27
|
+
- Tensors store data in a flat list with an explicit shape tuple.
|
|
28
|
+
- Broadcasting is limited to scalar-like tensors with `size == 1`.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# maten.frame
|
|
2
|
+
|
|
3
|
+
Pandas-like tabular data structures.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from maten.frame import DataFrame, Series
|
|
9
|
+
|
|
10
|
+
df = DataFrame({"name": ["a", "b"], "score": [10, 20]})
|
|
11
|
+
print(df.describe())
|
|
12
|
+
print(df.groupby("name").mean("score"))
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## API overview
|
|
16
|
+
|
|
17
|
+
| Module | Purpose |
|
|
18
|
+
|--------|---------|
|
|
19
|
+
| `series.py` | Labeled 1-D `Series` |
|
|
20
|
+
| `dataframe.py` | Column-oriented `DataFrame` |
|
|
21
|
+
| `groupby.py` | Split-apply-combine aggregations |
|
|
22
|
+
| `io.py` | `read_csv`, `read_json`, `concat` |
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# maten.neural
|
|
2
|
+
|
|
3
|
+
Minimal autograd and training utilities inspired by micrograd and TensorFlow APIs.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from maten.neural import Linear, ReLU, Sequential, SGD, Value
|
|
9
|
+
from maten.neural.losses import mse
|
|
10
|
+
|
|
11
|
+
model = Sequential([Linear(2, 4), ReLU(), Linear(4, 1)])
|
|
12
|
+
opt = SGD(model.parameters(), lr=0.01)
|
|
13
|
+
|
|
14
|
+
x = [Value(1.0), Value(-1.0)]
|
|
15
|
+
y = [Value(0.5)]
|
|
16
|
+
|
|
17
|
+
opt.zero_grad()
|
|
18
|
+
pred = model(x)
|
|
19
|
+
loss = mse(pred, y)
|
|
20
|
+
loss.backward()
|
|
21
|
+
opt.step()
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API overview
|
|
25
|
+
|
|
26
|
+
| Module | Purpose |
|
|
27
|
+
|--------|---------|
|
|
28
|
+
| `autograd.py` | Differentiable `Value` scalar |
|
|
29
|
+
| `tensor.py` | Batched `Value` containers |
|
|
30
|
+
| `layers.py` | `Linear`, `ReLU`, `Dropout`, `BatchNorm` |
|
|
31
|
+
| `losses.py` | `mse`, `bce`, `cross_entropy` |
|
|
32
|
+
| `optimizers.py` | `SGD`, `Adam`, `RMSProp` |
|
|
33
|
+
| `sequential.py` | `Module`, `Sequential` |
|
|
34
|
+
| `dataloader.py` | `DataLoader`, `Trainer` |
|
|
35
|
+
| `metrics.py` | `accuracy`, `mse`, `r2_score` |
|
maten-0.1.0/docs/plot.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# maten.plot
|
|
2
|
+
|
|
3
|
+
Matplotlib-inspired plotting that renders SVG.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from maten.plot import subplots, line, bar
|
|
9
|
+
|
|
10
|
+
_, ax = subplots()
|
|
11
|
+
line(ax, [0, 1, 2], [0, 1, 4])
|
|
12
|
+
bar(ax, ["A", "B"], [3, 7])
|
|
13
|
+
ax.save("chart.svg")
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## API overview
|
|
17
|
+
|
|
18
|
+
| Module | Purpose |
|
|
19
|
+
|--------|---------|
|
|
20
|
+
| `figure.py` | `Figure`, `Axes`, `subplots` |
|
|
21
|
+
| `charts.py` | `line`, `scatter`, `bar`, `hist`, `pie`, `heatmap` |
|
|
22
|
+
| `colors.py` | Named colors and categorical palettes |
|
|
23
|
+
| `utils.py` | SVG helpers and linear scaling |
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""
|
|
2
|
+
maten — Pure Python scientific computing library
|
|
3
|
+
=================================================
|
|
4
|
+
Single import replaces NumPy + Pandas + Matplotlib + TensorFlow.
|
|
5
|
+
|
|
6
|
+
import maten as mt
|
|
7
|
+
|
|
8
|
+
mt.array(...) # arrays
|
|
9
|
+
mt.DataFrame(...) # dataframes
|
|
10
|
+
mt.subplots() # plots
|
|
11
|
+
mt.Sequential(...) # neural networks
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
__version__ = "0.1.0"
|
|
15
|
+
__author__ = "maten contributors"
|
|
16
|
+
|
|
17
|
+
# ── core (NumPy replacement) ──────────────────────────────────
|
|
18
|
+
from maten.core.tensor import Tensor, array, matmul
|
|
19
|
+
from maten.core.creation import (zeros, ones, full, eye, arange, linspace,
|
|
20
|
+
rand, randn, randint, concatenate, stack)
|
|
21
|
+
from maten.core.math_ops import (sqrt, exp, log, log2, log10,
|
|
22
|
+
sin, cos, tan, tanh,
|
|
23
|
+
abs_, ceil, floor,
|
|
24
|
+
sigmoid, relu, leaky_relu,
|
|
25
|
+
clip, softmax, where, unique, sort)
|
|
26
|
+
from maten.core.linalg import linalg
|
|
27
|
+
|
|
28
|
+
# ── frame (Pandas replacement) ────────────────────────────────
|
|
29
|
+
from maten.frame.series import Series
|
|
30
|
+
from maten.frame.dataframe import DataFrame
|
|
31
|
+
from maten.frame.groupby import GroupBy
|
|
32
|
+
from maten.frame.io import read_csv, read_json, concat as concat_frames
|
|
33
|
+
|
|
34
|
+
# ── plot (Matplotlib replacement) ─────────────────────────────
|
|
35
|
+
from maten.plot.figure import (Figure, Axes,
|
|
36
|
+
figure, subplots, show, savefig,
|
|
37
|
+
plot, scatter, bar, barh, hist,
|
|
38
|
+
fill_between, axhline, axvline,
|
|
39
|
+
xlabel, ylabel, title, legend, xlim, ylim)
|
|
40
|
+
from maten.plot.charts import pie, heatmap
|
|
41
|
+
|
|
42
|
+
# ── neural (TensorFlow replacement) ───────────────────────────
|
|
43
|
+
from maten.neural.autograd import Value
|
|
44
|
+
from maten.neural.sequential import Module, Sequential
|
|
45
|
+
from maten.neural.layers import (Parameter, Linear,
|
|
46
|
+
ReLU, Sigmoid, Tanh, Softmax,
|
|
47
|
+
LeakyReLU, Dropout, BatchNorm1d, Flatten)
|
|
48
|
+
from maten.neural.losses import (MSELoss, MAELoss, BCELoss,
|
|
49
|
+
CrossEntropyLoss, HuberLoss)
|
|
50
|
+
from maten.neural.optimizers import SGD, Adam, AdamW, RMSProp, Adagrad
|
|
51
|
+
from maten.neural.metrics import (accuracy, mean_squared_error,
|
|
52
|
+
mean_absolute_error, r2_score, rmse,
|
|
53
|
+
precision, recall, f1_score, confusion_matrix)
|
|
54
|
+
from maten.neural.dataloader import DataLoader, Trainer
|
|
55
|
+
|
|
56
|
+
# ── neural tensor (separate namespace to avoid clash with core)
|
|
57
|
+
from maten.neural import tensor as nn_tensor
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""
|
|
2
|
+
maten.core.creation — array creation functions
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import random
|
|
6
|
+
from functools import reduce
|
|
7
|
+
import operator
|
|
8
|
+
from maten.core.tensor import Tensor
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def zeros(shape, dtype=float):
|
|
12
|
+
if isinstance(shape, int): shape = (shape,)
|
|
13
|
+
size = reduce(operator.mul, shape, 1)
|
|
14
|
+
return Tensor._make([dtype(0)] * size, shape, dtype)
|
|
15
|
+
|
|
16
|
+
def ones(shape, dtype=float):
|
|
17
|
+
if isinstance(shape, int): shape = (shape,)
|
|
18
|
+
size = reduce(operator.mul, shape, 1)
|
|
19
|
+
return Tensor._make([dtype(1)] * size, shape, dtype)
|
|
20
|
+
|
|
21
|
+
def full(shape, fill_value, dtype=float):
|
|
22
|
+
if isinstance(shape, int): shape = (shape,)
|
|
23
|
+
size = reduce(operator.mul, shape, 1)
|
|
24
|
+
return Tensor._make([dtype(fill_value)] * size, shape, dtype)
|
|
25
|
+
|
|
26
|
+
def eye(n, dtype=float):
|
|
27
|
+
t = zeros((n, n), dtype=dtype)
|
|
28
|
+
for i in range(n):
|
|
29
|
+
t._data[i * n + i] = dtype(1)
|
|
30
|
+
return t
|
|
31
|
+
|
|
32
|
+
def arange(start, stop=None, step=1, dtype=float):
|
|
33
|
+
if stop is None: start, stop = 0, start
|
|
34
|
+
data, v = [], start
|
|
35
|
+
while (step > 0 and v < stop) or (step < 0 and v > stop):
|
|
36
|
+
data.append(dtype(v)); v += step
|
|
37
|
+
return Tensor._make(data, (len(data),), dtype)
|
|
38
|
+
|
|
39
|
+
def linspace(start, stop, num=50, dtype=float):
|
|
40
|
+
if num == 1:
|
|
41
|
+
return Tensor._make([dtype(start)], (1,), dtype)
|
|
42
|
+
step = (stop - start) / (num - 1)
|
|
43
|
+
data = [dtype(start + i * step) for i in range(num)]
|
|
44
|
+
return Tensor._make(data, (num,), dtype)
|
|
45
|
+
|
|
46
|
+
def rand(*shape):
|
|
47
|
+
size = reduce(operator.mul, shape, 1)
|
|
48
|
+
return Tensor._make([random.random() for _ in range(size)], shape, float)
|
|
49
|
+
|
|
50
|
+
def randn(*shape):
|
|
51
|
+
size = reduce(operator.mul, shape, 1)
|
|
52
|
+
return Tensor._make([random.gauss(0, 1) for _ in range(size)], shape, float)
|
|
53
|
+
|
|
54
|
+
def randint(low, high, shape):
|
|
55
|
+
if isinstance(shape, int): shape = (shape,)
|
|
56
|
+
size = reduce(operator.mul, shape, 1)
|
|
57
|
+
return Tensor._make([float(random.randint(low, high - 1)) for _ in range(size)], shape, float)
|
|
58
|
+
|
|
59
|
+
def concatenate(tensors, axis=0):
|
|
60
|
+
if axis == 0:
|
|
61
|
+
data = []
|
|
62
|
+
for t in tensors: data.extend(t._data)
|
|
63
|
+
new_shape = (sum(t._shape[0] for t in tensors),) + tensors[0]._shape[1:]
|
|
64
|
+
return Tensor._make(data, new_shape, tensors[0].dtype)
|
|
65
|
+
raise NotImplementedError("concatenate on axis != 0 coming soon")
|
|
66
|
+
|
|
67
|
+
def stack(tensors, axis=0):
|
|
68
|
+
return concatenate([t.expand_dims(axis) for t in tensors], axis=axis)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
maten.core.linalg — linear algebra operations
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
import operator
|
|
7
|
+
from functools import reduce
|
|
8
|
+
from maten.core.tensor import Tensor, matmul
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class linalg:
|
|
12
|
+
|
|
13
|
+
@staticmethod
|
|
14
|
+
def norm(t, ord=2):
|
|
15
|
+
if ord == 2: return Tensor._make([math.sqrt(sum(x**2 for x in t._data))], (1,), float)
|
|
16
|
+
elif ord == 1: return Tensor._make([sum(abs(x) for x in t._data)], (1,), float)
|
|
17
|
+
elif ord == float('inf'): return Tensor._make([max(abs(x) for x in t._data)], (1,), float)
|
|
18
|
+
raise ValueError(f"Unsupported norm order: {ord}")
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def dot(a, b):
|
|
22
|
+
return a.dot(b)
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def matmul(a, b):
|
|
26
|
+
return matmul(a, b)
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def transpose(t):
|
|
30
|
+
return t.T
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def trace(t):
|
|
34
|
+
assert t.ndim == 2 and t._shape[0] == t._shape[1]
|
|
35
|
+
n = t._shape[0]
|
|
36
|
+
return Tensor._make([sum(t._data[i * n + i] for i in range(n))], (1,), float)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def det(t):
|
|
40
|
+
assert t.ndim == 2 and t._shape[0] == t._shape[1]
|
|
41
|
+
n = t._shape[0]
|
|
42
|
+
from maten.core.tensor import _make_nested
|
|
43
|
+
mat = [row[:] for row in _make_nested(t._data, t._shape)]
|
|
44
|
+
det = 1.0
|
|
45
|
+
for col in range(n):
|
|
46
|
+
pivot = next((r for r in range(col, n) if abs(mat[r][col]) > 1e-12), None)
|
|
47
|
+
if pivot is None: return Tensor._make([0.0], (1,), float)
|
|
48
|
+
if pivot != col:
|
|
49
|
+
mat[col], mat[pivot] = mat[pivot], mat[col]; det *= -1
|
|
50
|
+
det *= mat[col][col]
|
|
51
|
+
for row in range(col + 1, n):
|
|
52
|
+
f = mat[row][col] / mat[col][col]
|
|
53
|
+
for k in range(col, n):
|
|
54
|
+
mat[row][k] -= f * mat[col][k]
|
|
55
|
+
return Tensor._make([det], (1,), float)
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def inv(t):
|
|
59
|
+
assert t.ndim == 2 and t._shape[0] == t._shape[1]
|
|
60
|
+
n = t._shape[0]
|
|
61
|
+
from maten.core.tensor import _make_nested
|
|
62
|
+
mat = [row[:] for row in _make_nested(t._data, t._shape)]
|
|
63
|
+
inv = [[float(i == j) for j in range(n)] for i in range(n)]
|
|
64
|
+
for col in range(n):
|
|
65
|
+
pivot = next((r for r in range(col, n) if abs(mat[r][col]) > 1e-12), None)
|
|
66
|
+
if pivot is None: raise ValueError("Matrix is singular")
|
|
67
|
+
mat[col], mat[pivot] = mat[pivot], mat[col]
|
|
68
|
+
inv[col], inv[pivot] = inv[pivot], inv[col]
|
|
69
|
+
scale = mat[col][col]
|
|
70
|
+
mat[col] = [v / scale for v in mat[col]]
|
|
71
|
+
inv[col] = [v / scale for v in inv[col]]
|
|
72
|
+
for row in range(n):
|
|
73
|
+
if row != col:
|
|
74
|
+
f = mat[row][col]
|
|
75
|
+
mat[row] = [mat[row][k] - f * mat[col][k] for k in range(n)]
|
|
76
|
+
inv[row] = [inv[row][k] - f * inv[col][k] for k in range(n)]
|
|
77
|
+
flat = [v for row in inv for v in row]
|
|
78
|
+
return Tensor._make(flat, (n, n), float)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
maten.core.math_ops — mathematical functions
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from maten.core.tensor import Tensor
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _apply(t, func):
|
|
10
|
+
if isinstance(t, (int, float)): return func(t)
|
|
11
|
+
return t.apply(func)
|
|
12
|
+
|
|
13
|
+
def sqrt(t): return _apply(t, math.sqrt)
|
|
14
|
+
def exp(t): return _apply(t, math.exp)
|
|
15
|
+
def log(t): return _apply(t, math.log)
|
|
16
|
+
def log2(t): return _apply(t, math.log2)
|
|
17
|
+
def log10(t): return _apply(t, math.log10)
|
|
18
|
+
def sin(t): return _apply(t, math.sin)
|
|
19
|
+
def cos(t): return _apply(t, math.cos)
|
|
20
|
+
def tan(t): return _apply(t, math.tan)
|
|
21
|
+
def tanh(t): return _apply(t, math.tanh)
|
|
22
|
+
def abs_(t): return _apply(t, abs)
|
|
23
|
+
def ceil(t): return _apply(t, math.ceil)
|
|
24
|
+
def floor(t): return _apply(t, math.floor)
|
|
25
|
+
|
|
26
|
+
def sigmoid(t):
|
|
27
|
+
return _apply(t, lambda x: 1 / (1 + math.exp(-x)))
|
|
28
|
+
|
|
29
|
+
def relu(t):
|
|
30
|
+
return _apply(t, lambda x: max(0.0, x))
|
|
31
|
+
|
|
32
|
+
def leaky_relu(t, alpha=0.01):
|
|
33
|
+
return _apply(t, lambda x: x if x > 0 else alpha * x)
|
|
34
|
+
|
|
35
|
+
def clip(t, min_val, max_val):
|
|
36
|
+
return _apply(t, lambda x: max(min_val, min(max_val, x)))
|
|
37
|
+
|
|
38
|
+
def softmax(t):
|
|
39
|
+
m = max(t._data)
|
|
40
|
+
exps = [math.exp(x - m) for x in t._data]
|
|
41
|
+
total = sum(exps)
|
|
42
|
+
return Tensor._make([e / total for e in exps], t._shape, float)
|
|
43
|
+
|
|
44
|
+
def where(condition, x, y):
|
|
45
|
+
data = [a if c else b for c, a, b in zip(condition._data, x._data, y._data)]
|
|
46
|
+
return Tensor._make(data, condition._shape, x.dtype)
|
|
47
|
+
|
|
48
|
+
def unique(t):
|
|
49
|
+
return sorted(set(t._data))
|
|
50
|
+
|
|
51
|
+
def sort(t):
|
|
52
|
+
return Tensor._make(sorted(t._data), t._shape, t.dtype)
|
|
53
|
+
|
|
54
|
+
def matmul(a, b):
|
|
55
|
+
from maten.core.tensor import matmul as _matmul
|
|
56
|
+
return _matmul(a, b)
|