Пример #1
0
def cascadeS(S1, S2, *rest):
    """Cascade arrays containing S-parameters.
    """
    S1, S2 = make_same_dims(S1, S2)
    neworder = tuple([x for x in S1.dims if not isinstance(x, _DimMatrix)])
    S1 = S1.reorder_dimensions(*neworder)
    S2 = S2.reorder_dimensions(*neworder)
    denom = 1 - S1[..., 1, 1] * S2[..., 0, 0]
    s1det = det(S1)
    s2det = det(S2)
    maxshape = tuple(max(x) for x in zip(S1.shape, S2.shape))
    res = S1.__class__(np.zeros(maxshape, S1.dtype), dims=S1.dims)
    res[..., 0, 0] = S1[..., 0, 0] - S2[..., 0, 0] * s1det
    res[..., 0, 1] = S1[..., 0, 1] * S2[..., 0, 1]
    res[..., 1, 0] = S1[..., 1, 0] * S2[..., 1, 0]
    res[..., 1, 1] = S2[..., 1, 1] - S1[..., 1, 1] * s2det
    res = res / denom
    res = S1.__class__(res, dims=S1.dims)
    return res
Пример #2
0
def cascadeS(S1, S2, *rest):
    """Cascade arrays containing S-parameters.
    """
    S1, S2 = make_same_dims(S1, S2)
    neworder = tuple([x for x in S1.dims if not isinstance(x, _DimMatrix)])
    S1 = S1.reorder_dimensions(*neworder)
    S2 = S2.reorder_dimensions(*neworder)
    denom = (1 - S1[..., 1, 1] * S2[..., 0, 0])
    s1det = det(S1)
    s2det = det(S2)
    maxshape = tuple(max(x) for x in zip(S1.shape, S2.shape))
    res = S1.__class__(np.zeros(maxshape, S1.dtype), dims=S1.dims)
    res[..., 0, 0] = S1[..., 0, 0] - S2[..., 0, 0] * s1det
    res[..., 0, 1] = S1[..., 0, 1] * S2[..., 0, 1]
    res[..., 1, 0] = S1[..., 1, 0] * S2[..., 1, 0]
    res[..., 1, 1] = S2[..., 1, 1] - S1[..., 1, 1] * s2det
    res = res / denom
    res = S1.__class__(res, dims=S1.dims)
    return res
Пример #3
0
 def test_1(self):
     res = hfmath.det(self.m)
     self.assertAllclose(res, -2)
     self.assertEqual(res.shape, (3, ))
     self.assertEqual(res.dims, (self.J, ))