MCPcopy Index your code
hub / github.com/CadQuery/cadquery / designMatrix2D

Function designMatrix2D

cadquery/occ_impl/nurbs.py:1000–1072  ·  view source on GitHub ↗

Create a sparse tensor product design matrix.

(
    u: Array,
    v: Array,
    uorder: int,
    vorder: int,
    uknots: Array,
    vknots: Array,
    uperiodic: bool = False,
    vperiodic: bool = False,
)

Source from the content-addressed store, hash-verified

998
999@njit
1000def designMatrix2D(
1001 u: Array,
1002 v: Array,
1003 uorder: int,
1004 vorder: int,
1005 uknots: Array,
1006 vknots: Array,
1007 uperiodic: bool = False,
1008 vperiodic: bool = False,
1009) -> COO:
1010 """
1011 Create a sparse tensor product design matrix.
1012 """
1013
1014 # extend the knots and pre-process
1015 u_, uknots_ext, minspanu, maxspanu, deltaspanu = _preprocess(
1016 u, uorder, uknots, uperiodic
1017 )
1018 v_, vknots_ext, minspanv, maxspanv, deltaspanv = _preprocess(
1019 v, vorder, vknots, vperiodic
1020 )
1021
1022 # number of parameter values
1023 ni = len(u)
1024
1025 # chunk size
1026 nu = uorder + 1
1027 nv = vorder + 1
1028 nj = nu * nv
1029
1030 # number of basis
1031 nu_total = maxspanu
1032 nv_total = maxspanv
1033
1034 # temp chunk storage
1035 utemp = np.zeros(nu)
1036 vtemp = np.zeros(nv)
1037
1038 # initialize the empty matrix
1039 rv = COO(
1040 i=np.empty(ni * nj, dtype=np.int64),
1041 j=np.empty(ni * nj, dtype=np.int64),
1042 v=np.empty(ni * nj),
1043 shape=(
1044 ni,
1045 (len(uknots) - 1 - (not uperiodic) * uorder)
1046 * (len(vknots) - 1 - (not vperiodic) * vorder),
1047 ),
1048 )
1049
1050 # loop over parameter values
1051 for i in range(ni):
1052 ui, vi = u_[i], v_[i]
1053
1054 # find the supporting span
1055 uspan = nbFindSpan(ui, uorder, uknots, minspanu, maxspanu) + deltaspanu
1056 vspan = nbFindSpan(vi, vorder, vknots, minspanv, maxspanv) + deltaspanv
1057

Callers 3

test_dm_2dFunction · 0.90
approximate2DFunction · 0.85
constrainedApproximate2DFunction · 0.85

Calls 4

_preprocessFunction · 0.85
COOClass · 0.85
nbFindSpanFunction · 0.85
nbBasisFunction · 0.85

Tested by 1

test_dm_2dFunction · 0.72