Skip to content

Commit

Permalink
update python3 wrapper configuration and github action file.
Browse files Browse the repository at this point in the history
  • Loading branch information
bassoy committed Mar 8, 2024
1 parent 8608a72 commit b0307c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup C++ environment
- name: Setup C++ Environment
run: |
sudo apt update && sudo apt install -y g++ libomp-dev libopenblas-dev libmkl-dev intel-mkl
sudo apt update && sudo apt install -y g++ libomp-dev libopenblas-dev libmkl-dev intel-mkl python3-pip python3-virtualenv
- name: Install Gtest
run: |
Expand All @@ -28,27 +28,29 @@ jobs:
make -j
sudo make install
- name: Git clone TTM repo
- name: Git Clone TTM Repo
run: |
cd ${GITHUB_WORKSPACE}
git clone https://github.com/bassoy/ttm.git
- name: Build and run tests (Intel MKL)
- name: Build and Run Tests (Intel MKL)
run: |
cd ttm/test
make clean && make -j BLAS_FLAG=MKL
./bin/main
- name: Build and run tests (OpenBLAS)
- name: Build and Run Tests (OpenBLAS)
run: |
cd ttm/test
make clean && make -j BLAS_FLAG=OPENBLAS
./bin/main
- name: Build and run examples (Intel MKL)
- name: Build and Run Python Wrapper Tests (OpenBLAS)
run: |
cd ttm/example
make clean && make -j BLAS_FLAG=MKL
./interface1
./interface2
./interface3
cd ttm/ttmpy
virtualenv ~/env-ttm
source ~/env-ttm/bin/activate
pip install -e .
cd tests
python3 -m unittest discover -v
deactivate
26 changes: 19 additions & 7 deletions ttmpy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,36 @@ cd ttm

Install OpenBLAS and MLK
```bash
sudo apt install libopenblas-base libopenblas-dev libomp-dev
sudo apt install libopenblas-dev libopenblas64-pthread-dev libomp-dev python3-pip python3-virtualenv
```

Navigate to the python wrapper folder
```bash
cd ttmpy
```

Activate the virtual environment `env-ttm`
```bash
virtualenv ~/env-ttm
source ~/env-ttm/bin/activate
```

Install the pacakge in editable mode
```bash
pip install -e .
# python3 setup.py build_ext -i
```

Test the package
```bash
cd tests
python3 -m unittest discover -v
```

Deactivate the virtual environment `env-ttm`
```bash
deactivate
```


## Python Interface

Expand All @@ -36,7 +47,7 @@ C = ttm(q, A, b)
```
* `q` is the contraction mode with `1<=q<=A.ndim`
* `A` is an input `numpy.ndarray` with typically `A.ndim>=2`
* `b` is an input `numpy.ndarray` with `b.ndim=2` and `b.shape[1]=A.shape[q-1]` and `b.shape[0]=C.shape[q-1]`
* `B` is an input `numpy.ndarray` with `b.ndim=2` and `b.shape[1]=A.shape[q-1]` and `b.shape[0]=C.shape[q-1]`
* `C` is the output `numpy.ndarray` with `A.ndim`

## Python Example
Expand All @@ -46,8 +57,9 @@ C = ttm(q, A, b)
import numpy as np
import ttmpy as tp

A = np.arange(3*2*4, dtype=np.float64).reshape(3, 2, 4)
b = np.arange(3, dtype=np.float64)
C = ttm(1,A,b)
# C = [[40,43,46,49,],[52,55,58,61]]
A = np.arange(4*3*2, dtype=np.float64).reshape(4,3,2)
B = np.arange(5*4, dtype=np.float64).reshape(5,4)
C = tp.ttm(1,A,B)
D = np.einsum("ijk,xi->xjk", A, B)
np.all(np.equal(C,D))
```
2 changes: 1 addition & 1 deletion ttmpy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def build_extensions(self):

setup(
name='ttmpy',
version='0.0.2',
version='0.0.1',
author='Cem Bassoy',
author_email='[email protected]',
description='Python module for fast tensor-times-matrix multiplication',
Expand Down

0 comments on commit b0307c5

Please sign in to comment.