コード例 #1
0
 def test_ternary(self):
     m = numeric.meshgrid([1, 2, 3], 1j, [.4, .5])
     self.assertEqual(m.dtype, complex)
     self.assertEqual(m.shape, (3, 3, 2))
     self.assertAllEqual(
         m, [[[1, 1], [2, 2], [3, 3]], [[1j, 1j], [1j, 1j], [1j, 1j]],
             [[.4, .5], [.4, .5], [.4, .5]]])
コード例 #2
0
def rectilinear(richshape, periodic=(), name='rect', bnames=None):
    'rectilinear mesh'

    ndims = len(richshape)
    shape = []
    offset = []
    scale = []
    uniform = True
    for v in richshape:
        if numeric.isint(v):
            assert v > 0
            shape.append(v)
            scale.append(1)
            offset.append(0)
        elif np.equal(v, np.linspace(v[0], v[-1], len(v))).all():
            shape.append(len(v) - 1)
            scale.append((v[-1] - v[0]) / float(len(v) - 1))
            offset.append(v[0])
        else:
            shape.append(len(v) - 1)
            uniform = False

    if isinstance(name, str):
        wrap = tuple(sh if i in periodic else 0 for i, sh in enumerate(shape))
        root = transform.RootTrans(name, wrap)
    else:
        assert all(
            (name.take(0, i) == name.take(2, i)).all() for i in periodic)
        root = transform.RootTransEdges(name, shape)

    axes = [
        topology.DimAxis(0, n, idim in periodic)
        for idim, n in enumerate(shape)
    ]
    topo = topology.StructuredTopology(root, axes, bnames=bnames)

    if uniform:
        if all(o == offset[0] for o in offset[1:]):
            offset = offset[0]
        if all(s == scale[0] for s in scale[1:]):
            scale = scale[0]
        geom = function.rootcoords(ndims) * scale + offset
    else:
        funcsp = topo.splinefunc(degree=1, periodic=())
        coords = numeric.meshgrid(*richshape).reshape(ndims, -1)
        geom = (funcsp * coords).sum(-1)

    return topo, geom
コード例 #3
0
 def test_dtype(self):
   m = numeric.meshgrid(1, dtype=float)
   self.assertEqual(m.dtype, float)
   self.assertEqual(m.shape, (1,))
   self.assertAllEqual(m, 1)
コード例 #4
0
 def test_binary(self):
   m = numeric.meshgrid([1,2,3],[.4,.5])
   self.assertEqual(m.dtype, float)
   self.assertEqual(m.shape, (2,3,2))
   self.assertAllEqual(m, [[[1,1],[2,2],[3,3]],[[.4,.5],[.4,.5],[.4,.5]]])
コード例 #5
0
 def test_unary(self):
   m = numeric.meshgrid([1,2,3])
   self.assertEqual(m.dtype, int)
   self.assertEqual(m.shape, (1,3))
   self.assertAllEqual(m, [[1,2,3]])