Skip to content

Commit

Permalink
Merge pull request #98 from bab2min/dev
Browse files Browse the repository at this point in the history
fixed numpy version & fixed #62
  • Loading branch information
bab2min authored Mar 1, 2021
2 parents 77fcff0 + c46e975 commit ccae9aa
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 54 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
/opt/python/cp38-cp38/bin/python -m pip install twine wheel numpy
/opt/python/cp38-cp38/bin/python -m pip install twine wheel numpy==`/opt/python/cp38-cp38/bin/python test/numpy_version.py`
/opt/python/cp38-cp38/bin/python setup.py sdist
/opt/python/cp38-cp38/bin/python -m twine upload dist/*.tar.gz
for cp in cp35-cp35m cp36-cp36m cp37-cp37m cp38-cp38 cp39-cp39
do
/opt/python/${cp}/bin/python -m pip install twine wheel numpy
/opt/python/${cp}/bin/python -m pip install twine wheel numpy==`/opt/python/${cp}/bin/python test/numpy_version.py`
/opt/python/${cp}/bin/python setup.py build bdist_wheel
auditwheel repair dist/*-${cp}-linux_x86_64.whl
done
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
export AUDITWHEEL_PLAT=many
python -m pip install twine wheel numpy
python -m pip install twine wheel numpy==`python test/numpy_version.py`
python setup.py bdist_wheel
twine upload dist/*
Expand Down Expand Up @@ -122,6 +122,6 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m pip install twine wheel numpy
python -m pip install twine wheel numpy==$(python test/numpy_version.py)
python setup.py bdist_wheel
twine upload dist/*
8 changes: 4 additions & 4 deletions .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
/opt/python/cp35-cp35m/bin/python -m pip install twine wheel numpy
/opt/python/cp35-cp35m/bin/python -m pip install twine wheel numpy==`/opt/python/cp35-cp35m/bin/python test/numpy_version.py`
/opt/python/cp35-cp35m/bin/python setup.py sdist
/opt/python/cp35-cp35m/bin/python -m twine upload --repository testpypi dist/*.tar.gz
for cp in cp35-cp35m cp36-cp36m cp37-cp37m cp38-cp38
do
/opt/python/${cp}/bin/python -m pip install twine wheel numpy
/opt/python/${cp}/bin/python -m pip install twine wheel numpy==`/opt/python/${cp}/bin/python test/numpy_version.py`
/opt/python/${cp}/bin/python setup.py build bdist_wheel
auditwheel repair dist/*-${cp}-linux_x86_64.whl
done
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
export AUDITWHEEL_PLAT=many
python -m pip install twine wheel numpy
python -m pip install twine wheel numpy==`python test/numpy_version.py`
python setup.py bdist_wheel
twine upload --repository testpypi dist/*
Expand Down Expand Up @@ -121,6 +121,6 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m pip install twine wheel numpy
python -m pip install twine wheel numpy==$(python test/numpy_version.py)
python setup.py bdist_wheel
twine upload --repository testpypi dist/*
2 changes: 1 addition & 1 deletion .github/workflows/generate_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
mv variant/include/mapbox include/
- name: build
run: |
python3 -m pip install numpy
python3 -m pip install numpy==1.10.4
python3 -m pip install pdoc3==0.8.4
export TOMOTOPY_LANG=${{ matrix.language }}
python3 setup.py install
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pull_request_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
mv variant/include/mapbox include/
- name: Build
run: |
/opt/python/${{ matrix.cp }}/bin/python -m pip install numpy
/opt/python/${{ matrix.cp }}/bin/python -m pip install numpy==`/opt/python/${{ matrix.cp }}/bin/python test/numpy_version.py`
/opt/python/${{ matrix.cp }}/bin/python setup.py build install
- name: Test
run: |
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
mv variant-1.1.3/include/mapbox include/
- name: Build
run: |
python -m pip install numpy
python -m pip install numpy==`python test/numpy_version.py`
python setup.py build install
- name: Test
run: |
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
mv variant-1.1.3/include/mapbox include/
- name: Build
run: |
python -m pip install numpy
python -m pip install numpy==$(python test/numpy_version.py)
python setup.py build install
- name: Archive binary
uses: actions/upload-artifact@v2
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
"Operating System :: POSIX",
"Operating System :: MacOS"
],
install_requires=['numpy>=1.10.0'],
install_requires=['numpy>=1.11.0'],
keywords='NLP,Topic Model',

packages = ['tomotopy'],
packages=['tomotopy'],
include_package_data=True,
ext_modules = modules
ext_modules=modules
)
60 changes: 24 additions & 36 deletions src/TopicModel/HDPModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,52 +403,40 @@ namespace tomoto
if (_tw != TermWeight::one) doc.wordWeights.resize(wordSize);
}

template<bool _Infer>
template<bool _infer>
void updateStateWithDoc(typename BaseClass::Generator& g, _ModelState& ld, _RandGen& rgs, _DocType& doc, size_t i) const
{
// generate tables for each topic when inferring
if (_Infer)
Tid t;
std::vector<double> dist;
dist.emplace_back(this->alpha);
for (auto& d : doc.numTopicByTable) dist.emplace_back(d.num);
std::discrete_distribution<Tid> ddist{ dist.begin(), dist.end() };
t = ddist(rgs);
if (t == 0)
{
if (i < this->K)
// new table
Tid k;
if (_infer)
{
Tid t = i;
if (isLiveTopic(i))
std::uniform_int_distribution<> theta{ 0, this->K - 1 };
do
{
t = doc.addNewTable(i);
}
else
{
t = std::uniform_int_distribution<size_t>{ 0, doc.getNumTable() - 1 }(rgs);
}
++ld.numTableByTopic[doc.numTopicByTable[t].topic];
++ld.totalTable;
doc.Zs[i] = t;
}
else doc.Zs[i] = std::uniform_int_distribution<size_t>{ 0, doc.getNumTable() - 1 }(rgs);
}
// generate tables following CRP
else
{
Tid t;
std::vector<double> dist;
dist.emplace_back(this->alpha);
for (auto& d : doc.numTopicByTable) dist.emplace_back(d.num);
std::discrete_distribution<Tid> ddist{ dist.begin(), dist.end() };
t = ddist(rgs);
if (t == 0)
{
// new table
Tid k = g.theta(rgs);
t = doc.addNewTable(k);
++ld.numTableByTopic[k];
++ld.totalTable;
k = theta(rgs);
} while (!isLiveTopic(k));
}
else
{
t -= 1;
k = g.theta(rgs);
}
doc.Zs[i] = t;
t = doc.addNewTable(k);
++ld.numTableByTopic[k];
++ld.totalTable;
}
else
{
t -= 1;
}
doc.Zs[i] = t;
addWordTo<1>(ld, doc, i, doc.words[i], doc.Zs[i], doc.numTopicByTable[doc.Zs[i]].topic);
}

Expand Down
4 changes: 2 additions & 2 deletions src/TopicModel/TopicModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ namespace tomoto
{
if (doc.words.empty()) return -1;
if (!doc.docUid.empty() && uidMap.count(doc.docUid))
throw exception::InvalidArgument{ "there is a document with uid = " + std::string{ doc.docUid } + " already." };
throw exception::InvalidArgument{ "there is a document with uid = '" + std::string{ doc.docUid } + "' already." };
size_t maxWid = *std::max_element(doc.words.begin(), doc.words.end());
if (vocabCf.size() <= maxWid)
{
Expand All @@ -383,7 +383,7 @@ namespace tomoto
for (auto w : doc.words) ++vocabCf[w];
std::unordered_set<Vid> uniq{ doc.words.begin(), doc.words.end() };
for (auto w : uniq) ++vocabDf[w];
uidMap.emplace(doc.docUid, docs.size());
if (!doc.docUid.empty()) uidMap.emplace(doc.docUid, docs.size());
docs.emplace_back(std::forward<_DocTy>(doc));
return docs.size() - 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/SharedString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace tomoto

bool empty() const
{
return ptr == nullptr;
return ptr == nullptr || size() == 0;
}

operator std::string() const
Expand Down
14 changes: 14 additions & 0 deletions test/numpy_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

def get_old_numpy_version():
import sys

py_version = sys.version_info
if py_version >= (3, 9): return '1.20.0'
if py_version >= (3, 8): return '1.18.0'
if py_version >= (3, 7): return '1.15.0'
if py_version >= (3, 6): return '1.12.0'
if py_version >= (3, 5): return '1.11.0'
return '1.10.0'

if __name__ == '__main__':
print(get_old_numpy_version())

0 comments on commit ccae9aa

Please sign in to comment.