Skip to content

Commit

Permalink
Merge pull request #2 from nschloe/modernize
Browse files Browse the repository at this point in the history
Modernize
  • Loading branch information
nschloe committed May 15, 2019
2 parents 171ee7a + 4fc72ba commit 75ee204
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 97 deletions.
35 changes: 35 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2

jobs:
lint:
docker:
- image: ubuntu:18.04
steps:
- checkout
- run: apt update
- run: apt install -y python3-pip
- run: pip3 install -U black flake8
- run: LC_ALL=C.UTF-8 black --check setup.py vandermonde/ test/*.py
- run: flake8 setup.py vandermonde/ test/*.py
build:
working_directory: ~/work
docker:
- image: ubuntu:18.04
steps:
- run: apt-get update
- run: apt-get install -y git python3-pip
- run: pip3 install -U pytest pytest-cov
- checkout
# The actual test
- run: pip3 install .
- run: cd test/ && pytest --cov vandermonde
# submit to codecov
- run: apt-get install -y curl
- run: bash <(curl -s https://codecov.io/bash)

workflows:
version: 2
lint_and_build:
jobs:
- lint
- build
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503
max-line-length = 80
max-complexity = 18
select = B,C,E,F,W,T4,B9
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017 Nico Schlömer
Copyright (c) 2017, 2019 Nico Schlömer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
34 changes: 17 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
VERSION=$(shell python -c "import vandermonde; print(vandermonde.__version__)")

# Make sure we're on the master branch
ifneq "$(shell git rev-parse --abbrev-ref HEAD)" "master"
$(error Not on master branch)
endif

default:
@echo "\"make publish\"?"

README.rst: README.md
pandoc README.md -o README.rst
python setup.py check -r -s || exit 1

# https://packaging.python.org/distributing/#id72
upload: setup.py README.rst
rm -f dist/*
python setup.py bdist_wheel --universal
gpg --detach-sign -a dist/*
twine upload dist/*

tag:
@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
@echo "Tagging v$(VERSION)..."
git tag v$(VERSION)
git push --tags

upload: setup.py
@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
rm -f dist/*
python3 setup.py sdist
python3 setup.py bdist_wheel --universal
twine upload dist/*

publish: tag upload

clean:
rm -f README.rst
@find . | grep -E "(__pycache__|\.pyc|\.pyo$\)" | xargs rm -rf
@rm -rf *.egg-info/ build/ dist/

black:
black setup.py vandermonde/ test/*.py

lint:
black --check setup.py vandermonde/ test/*.py
flake8 setup.py vandermonde/ test/*.py
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# vandermonde

[![Build Status](https://travis-ci.org/nschloe/vandermonde.svg?branch=master)](https://travis-ci.org/nschloe/vandermonde)
[![codecov](https://codecov.io/gh/nschloe/vandermonde/branch/master/graph/badge.svg)](https://codecov.io/gh/nschloe/vandermonde)
[![PyPi Version](https://img.shields.io/pypi/v/vandermonde.svg)](https://pypi.python.org/pypi/vandermonde)
[![GitHub stars](https://img.shields.io/github/stars/nschloe/vandermonde.svg?style=social&label=Stars&maxAge=2592000)](https://github.com/nschloe/vandermonde)
[![CircleCI](https://img.shields.io/circleci/project/github/nschloe/vandermonde/master.svg)](https://circleci.com/gh/nschloe/vandermonde)
[![codecov](https://img.shields.io/codecov/c/github/nschloe/vandermonde.svg)](https://codecov.io/gh/nschloe/vandermonde)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![PyPi Version](https://img.shields.io/pypi/v/vandermonde.svg)](https://pypi.org/project/vandermonde)
[![Debian CI](https://badges.debian.net/badges/debian/testing/python3-vandermonde/version.svg)](https://tracker.debian.org/pkg/python-vandermonde)
[![GitHub stars](https://img.shields.io/github/stars/nschloe/vandermonde.svg?logo=github&label=Stars&logoColor=white)](https://github.com/nschloe/vandermonde)


vandermonde is a module with a handful of tools for working with [Vandermonde
matrices](https://en.wikipedia.org/wiki/Vandermonde_matrix).
Expand Down
60 changes: 24 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,36 @@
# https://packaging.python.org/single_source_version/
base_dir = os.path.abspath(os.path.dirname(__file__))
about = {}
with open(os.path.join(base_dir, 'vandermonde', '__about__.py'), 'rb') as f:
with open(os.path.join(base_dir, "vandermonde", "__about__.py"), "rb") as f:
exec(f.read(), about)


def read(fname):
try:
content = codecs.open(
os.path.join(os.path.dirname(__file__), fname),
encoding='utf-8'
).read()
except Exception:
content = ''
return content
return codecs.open(os.path.join(base_dir, fname), encoding="utf-8").read()


setup(
name='vandermonde',
version=about['__version__'],
author=about['__author__'],
author_email=about['__author_email__'],
name="vandermonde",
version=about["__version__"],
author=about["__author__"],
author_email=about["__author_email__"],
packages=find_packages(),
description=(
u'Vandermonde matrix tools'
),
long_description=read('README.rst'),
url='https://github.com/nschloe/vandermonde',
download_url='https://github.com/nschloe/vandermonde/releases',
license=about['__license__'],
platforms='any',
install_requires=[
'numpy'
],
description=(u"Vandermonde matrix tools"),
long_description=read("README.md"),
long_description_content_type="text/markdown",
url="https://github.com/nschloe/vandermonde",
license=about["__license__"],
platforms="any",
install_requires=["numpy"],
classifiers=[
about['__status__'],
about['__license__'],
'Intended Audience :: Science/Research',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Mathematics'
],
scripts=[
]
)
about["__status__"],
about["__license__"],
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Mathematics",
],
scripts=[],
)
12 changes: 7 additions & 5 deletions vandermonde/__about__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
#

__version__ = '0.1.1'
__author__ = u'Nico Schlömer'
__author_email__ = 'nico.schloemer@gmail.com'
__status__ = 'Development Status :: 4 - Beta'
__license__ = 'License :: OSI Approved :: MIT License'
__version__ = "0.1.2"
__author__ = u"Nico Schlömer"
__author_email__ = "nico.schloemer@gmail.com"
__copyright__ = u"Copyright (c) 2017,2019 {} <{}>".format(__author__, __author_email__)
__website__ = "https://github.com/nschloe/vandermonde"
__license__ = "License :: OSI Approved :: MIT License"
__status__ = "Development Status :: 4 - Beta"
16 changes: 14 additions & 2 deletions vandermonde/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
__author__,
__author_email__,
__status__,
__license__
)
__license__,
)

#
from .main import matrix, det, solve, solve_transpose

__all__ = [
"__version__",
"__author__",
"__author_email__",
"__status__",
"__license__",
"matrix",
"det",
"solve",
"solve_transpose",
]
20 changes: 9 additions & 11 deletions vandermonde/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def matrix(x):


def det(x):
return numpy.prod([
x[j] - x[i] for i in range(len(x)) for j in range(i+1, len(x))
])
return numpy.prod([numpy.prod(x[i + 1 :] - x[i]) for i in range(len(x))])


def solve(alpha, b):
Expand All @@ -20,11 +18,11 @@ def solve(alpha, b):
x = b.copy()

for k in range(1, n):
x[k:n] -= x[k-1:n-1]
x[k:n] /= alpha[k:n] - alpha[0:n-k]
x[k:n] -= x[k - 1 : n - 1]
x[k:n] /= alpha[k:n] - alpha[0 : n - k]

for k in range(n-1, 0, -1):
x[k-1:n-1] -= alpha[k-1] * x[k:n]
for k in range(n - 1, 0, -1):
x[k - 1 : n - 1] -= alpha[k - 1] * x[k:n]

return x

Expand All @@ -36,10 +34,10 @@ def solve_transpose(alpha, b):
x = b.copy()

for k in range(n):
x[k+1:n] -= alpha[k] * x[k:n-1]
x[k + 1 : n] -= alpha[k] * x[k : n - 1]

for k in range(n-1, 0, -1):
x[k:n] /= alpha[k:n] - alpha[:n-k]
x[k-1:n-1] -= x[k:n]
for k in range(n - 1, 0, -1):
x[k:n] /= alpha[k:n] - alpha[: n - k]
x[k - 1 : n - 1] -= x[k:n]

return x

0 comments on commit 75ee204

Please sign in to comment.