Skip to content

Commit

Permalink
Add example to CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtilly committed Nov 19, 2024
1 parent 06fd87a commit d803689
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
run: pixi run -e ${{ matrix.environment }} install-nightlies
- name: Install repository
run: pixi run -e ${{ matrix.environment }} postinstall
- name: Run Malte's example
run: pixi exec -e ${{ matrix.environment }} python example.py
- name: Run pytest
run: pixi run -e ${{ matrix.environment }} test -nauto -m "not high_memory"
- name: Run doctest
Expand Down
37 changes: 37 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import numpy as np

import tabmat

np.set_printoptions(suppress=True)

for dtype in [np.float32, np.float64]:
X = np.array(
[
[46.231056, 126.05263, 144.46439],
[46.231224, 128.66818, 0.7667693],
[46.231186, 104.97506, 193.8872],
[46.230835, 130.10156, 143.88954],
[46.230896, 116.76007, 7.5629334],
],
dtype=dtype,
)
v = np.array(
[0.12428328, 0.67062443, 0.6471895, 0.6153851, 0.38367754], dtype=dtype
)

weights = np.full(X.shape[0], 1 / X.shape[0], dtype=dtype)

stmat, out_means, col_stds = tabmat.DenseMatrix(X).standardize(weights, True, True)

print(stmat.toarray().T @ v)
print(stmat.transpose_matvec(v))

# compute by hand
res = np.zeros(X.shape[1], dtype=dtype)
for col in range(X.shape[1]):
res[col] += (
stmat.shift[col] + stmat.mult[col] * stmat.mat.toarray()[:, col]
) @ v

print(res)
print("\n")

0 comments on commit d803689

Please sign in to comment.