Skip to content

Commit

Permalink
Miscellaneous changes for CI
Browse files Browse the repository at this point in the history
- Use Extension class in setup.py
- Use only relative imports within splipy itself
- Do not import from the splipy root module, only from the source files
- Module names that are different from the root module re-exports
- Some cleanup of imports
  • Loading branch information
TheBB authored and VikingScientist committed May 31, 2021
1 parent 0f0bd46 commit 86e9d54
Show file tree
Hide file tree
Showing 35 changed files with 369 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
pip install -r requirements.dev.txt
- name: Install package
run: |
pip install .
pip install -vvv .
- name: Test with pytest
run: |
pytest --benchmark-skip
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ doc/_templates
/doc/html/
/doc/latex/
.dir-locals.el
/dist
16 changes: 12 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

from setuptools import setup
from distutils.extension import Extension
from setuptools import setup, find_packages
from Cython.Build import cythonize
import numpy as np

Expand All @@ -18,7 +19,7 @@
maintainer='Kjetil Andre Johannessen',
maintainer_email='kjetijo@gmail.com',
license='GNU public license v3',
packages=['splipy', 'splipy.utils', 'splipy.io'],
packages=find_packages(),
package_data={
'splipy': ['templates/*.bpt'],
},
Expand All @@ -30,8 +31,15 @@
'FiniteElement': ["nutils>=4.0"],
'Images': ["opencv-python>=4.0"],
},
ext_modules=cythonize("splipy/basis_eval.pyx"),
include_dirs=[np.get_include()],
# ext_modules=cythonize("splipy/basis_eval.pyx"),
ext_modules=cythonize([
Extension(
'splipy.basis_eval',
['splipy/basis_eval.pyx'],
include_dirs=[np.get_include()],
)
]),
# include_dirs=[np.get_include()],
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Multimedia :: Graphics :: 3D Modeling',
Expand Down
31 changes: 7 additions & 24 deletions splipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
# -*- coding: utf-8 -*-

from splipy.BSplineBasis import BSplineBasis
from splipy.SplineObject import SplineObject
from splipy.Curve import Curve
from splipy.Surface import Surface
from splipy.Volume import Volume
from splipy.TrimmedSurface import TrimmedSurface

# SplineModel imports io.G2 which imports TrimmedSurface,
# so we must import SplineModel after TrimmedSurface
from splipy.SplineModel import SplineModel
from .basis import BSplineBasis
from .splineobject import SplineObject
from .curve import Curve
from .surface import Surface
from .volume import Volume
from .trimmedsurface import TrimmedSurface
from .splinemodel import SplineModel

__version__ = '1.4.0'
__all__ = ['BSplineBasis',
'SplineObject',
'Curve',
'Surface',
'Volume',
'SplineModel',
'TrimmedSurface',
'curve_factory',
'surface_factory',
'volume_factory',
'utils',
'io']
10 changes: 6 additions & 4 deletions splipy/BSplineBasis.py → splipy/basis.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-

from splipy.utils import ensure_listlike
import splipy.state as state
from bisect import bisect_right, bisect_left
import numpy as np
import copy
from splipy import basis_eval

import numpy as np
from scipy.sparse import csr_matrix

from .utils import ensure_listlike
from . import basis_eval, state

__all__ = ['BSplineBasis']


Expand Down Expand Up @@ -118,6 +119,7 @@ def evaluate(self, t, d=0, from_right=True, sparse=False):
points *i*
:rtype: numpy.array
"""

# for single-value input, wrap it into a list so it don't crash on the loop below
t = ensure_listlike(t)
t = np.array(t, dtype=np.float64)
Expand Down
45 changes: 0 additions & 45 deletions splipy/bench_evaluation_test.py

This file was deleted.

12 changes: 7 additions & 5 deletions splipy/Curve.py → splipy/curve.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-

from splipy import BSplineBasis
from splipy import SplineObject
from splipy.utils import ensure_listlike, is_singleton
from itertools import chain
from bisect import bisect_left, bisect_right

import numpy as np
import scipy.sparse.linalg as splinalg

from .basis import BSplineBasis
from .splineobject import SplineObject
from .utils import ensure_listlike, is_singleton

__all__ = ['Curve']


Expand Down Expand Up @@ -414,9 +416,9 @@ def error(self, target):
this curve and a target curve
.. math:: ||\\boldsymbol{x_h}(t)-\\boldsymbol{x}(t)||_{L^2(t_1,t_2)}^2 = \\int_{t_1}^{t_2}
|\\boldsymbol{x_h}(t)-\\boldsymbol{x}(t)|^2 dt, \\quad \\forall \;\\text{knots}\;t_1 < t_2
|\\boldsymbol{x_h}(t)-\\boldsymbol{x}(t)|^2 dt, \\quad \\forall \\;\\text{knots}\\;t_1 < t_2
.. math:: ||\\boldsymbol{x_h}(t)-\\boldsymbol{x}(t)||_{L^\infty} = \\max_t |\\boldsymbol{x_h}(t)-\\boldsymbol{x}(t)|
.. math:: ||\\boldsymbol{x_h}(t)-\\boldsymbol{x}(t)||_{L^\\infty} = \\max_t |\\boldsymbol{x_h}(t)-\\boldsymbol{x}(t)|
:param function target: callable function which takes as input a vector
of evaluation points t and gives as output a matrix x where
Expand Down
17 changes: 10 additions & 7 deletions splipy/curve_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
"""Handy utilities for creating curves."""

from math import pi, cos, sin, sqrt, ceil, atan2
from splipy import Curve, BSplineBasis
from splipy.utils import flip_and_move_plane_geometry, rotate_local_x_axis
from numpy.linalg import norm
import splipy.state as state
import scipy.sparse.linalg as splinalg
import numpy as np
import scipy.sparse as sp
import copy
import inspect

import numpy as np
from numpy.linalg import norm
import scipy.sparse as sp
import scipy.sparse.linalg as splinalg

from .curve import Curve
from .basis import BSplineBasis
from .utils import flip_and_move_plane_geometry, rotate_local_x_axis
from . import state

__all__ = ['Boundary', 'line', 'polygon', 'n_gon', 'circle', 'ellipse',
'circle_segment_from_three_points', 'circle_segment', 'interpolate',
'least_square_fit', 'cubic_curve', 'bezier', 'manipulate', 'fit']
Expand Down
38 changes: 22 additions & 16 deletions splipy/io/g2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import numpy as np
from itertools import chain, product
from splipy import Curve, Surface, Volume, SplineObject, BSplineBasis, TrimmedSurface
from splipy.utils import flip_and_move_plane_geometry, rotate_local_x_axis
from .master import MasterIO
import splipy.surface_factory as SurfaceFactory
import splipy.curve_factory as CurveFactory
import splipy.state as state

import numpy as np
from numpy import sqrt, pi, savetxt

from ..curve import Curve
from ..surface import Surface
from ..volume import Volume
from ..splineobject import SplineObject
from ..basis import BSplineBasis
from ..trimmedsurface import TrimmedSurface
from ..utils import flip_and_move_plane_geometry, rotate_local_x_axis
from .. import surface_factory, curve_factory, state

from .master import MasterIO


class G2(MasterIO):

Expand All @@ -26,7 +32,7 @@ def circle(self):
param = np.array(next(self.fstream).split(), dtype=float)
reverse = next(self.fstream).strip() != '0'

result = CurveFactory.circle(r=r, center=center, normal=normal, xaxis=xaxis)
result = curve_factory.circle(r=r, center=center, normal=normal, xaxis=xaxis)
result.reparam(param)
if reverse:
result.reverse()
Expand All @@ -42,7 +48,7 @@ def ellipse(self):
param = np.array(next(self.fstream).split(), dtype=float)
reverse = next(self.fstream).strip() != '0'

result = CurveFactory.ellipse(r1=r1, r2=r2, center=center, normal=normal, xaxis=xaxis)
result = curve_factory.ellipse(r1=r1, r2=r2, center=center, normal=normal, xaxis=xaxis)
result.reparam(param)
if reverse:
result.reverse()
Expand All @@ -61,7 +67,7 @@ def line(self):
if not finite:
param = [-state.unlimited, +state.unlimited]

result = CurveFactory.line(s+d*param[0], s+d*param[1])
result = curve_factory.line(s+d*param[0], s+d*param[1])
if reverse:
result.reverse()
return result
Expand Down Expand Up @@ -96,7 +102,7 @@ def cylinder(self):

center = center + z_axis*param_v[0]
h = param_v[1] - param_v[0]
result = SurfaceFactory.cylinder(r=r, center=center, xaxis=x_axis, axis=z_axis, h=h)
result = surface_factory.cylinder(r=r, center=center, xaxis=x_axis, axis=z_axis, h=h)
result.reparam(param_u, param_v)
if swap:
result.swap()
Expand All @@ -115,11 +121,11 @@ def disc(self):
swap = next(self.fstream).strip() != '0'

if degen:
result = SurfaceFactory.disc(r=r, center=center, xaxis=x_axis, normal=z_axis, type='radial')
result = surface_factory.disc(r=r, center=center, xaxis=x_axis, normal=z_axis, type='radial')
else:
if not(np.allclose(np.diff(angles), pi/2, atol=1e-10)):
raise RuntimeError('Unknown square parametrization of disc elementary surface')
result = SurfaceFactory.disc(r=r, center=center, xaxis=x_axis, normal=z_axis, type='square')
result = surface_factory.disc(r=r, center=center, xaxis=x_axis, normal=z_axis, type='square')
result.reparam(param_u, param_v)
if swap:
result.swap()
Expand Down Expand Up @@ -159,7 +165,7 @@ def torus(self):
param_v = np.array(next(self.fstream).split(), dtype=float)
swap = next(self.fstream).strip() != '0'

result = SurfaceFactory.torus(minor_r=r1, major_r=r2, center=center, normal=z_axis, xaxis=x_axis)
result = surface_factory.torus(minor_r=r1, major_r=r2, center=center, normal=z_axis, xaxis=x_axis)
result.reparam(param_u, param_v)
if(swap):
result.swap()
Expand All @@ -175,7 +181,7 @@ def sphere(self):
param_v = np.array(next(self.fstream).split(), dtype=float)
swap = next(self.fstream).strip() != '0'

result = SurfaceFactory.sphere(r=r, center=center, xaxis=x_axis, zaxis=z_axis).swap()
result = surface_factory.sphere(r=r, center=center, xaxis=x_axis, zaxis=z_axis).swap()
if swap:
result.swap()
result.reparam(param_u, param_v)
Expand Down Expand Up @@ -210,7 +216,7 @@ def surface_of_linear_extrusion(self):
param_v=[-state.unlimited, +state.unlimited]
swap = next(self.fstream).strip() != '0'

result = SurfaceFactory.extrude(crv + normal*param_v[0], normal*(param_v[1]-param_v[0]))
result = surface_factory.extrude(crv + normal*param_v[0], normal*(param_v[1]-param_v[0]))
result.reparam(param_u, param_v)

if swap:
Expand Down
22 changes: 14 additions & 8 deletions splipy/io/grdecl.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import numpy as np
from itertools import product, chain
from splipy import Surface, Volume, SplineObject, BSplineBasis
from splipy import surface_factory, volume_factory, curve_factory
from splipy.io import G2
from splipy.utils import ensure_listlike
from .master import MasterIO
import re
import warnings
from scipy.spatial import Delaunay
from scipy.spatial.qhull import QhullError

import numpy as np
from tqdm import tqdm
import cv2
import h5py
from scipy.spatial import Delaunay
from scipy.spatial.qhull import QhullError

from ..surface import Surface
from ..volume import Volume
from ..splineobject import SplineObject
from ..basis import BSplineBasis
from ..utils import ensure_listlike
from .. import surface_factory, curve_factory, volume_factory

from .master import MasterIO
from .g2 import G2


class Box(object):
Expand Down
5 changes: 3 additions & 2 deletions splipy/io/ofoam.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from itertools import groupby
import numpy as np
from operator import itemgetter
from os.path import exists, isdir, join
from os import makedirs

from splipy import SplineModel
import numpy as np

from ..splinemodel import SplineModel


class OpenFOAM(object):
Expand Down
11 changes: 9 additions & 2 deletions splipy/io/spl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import numpy as np
from itertools import islice
from splipy import Curve, Surface, Volume, SplineObject, BSplineBasis

import numpy as np

from ..curve import Curve
from ..surface import Surface
from ..volume import Volume
from ..splineobject import SplineObject
from ..basis import BSplineBasis

from .master import MasterIO


Expand Down
Loading

0 comments on commit 86e9d54

Please sign in to comment.