예제 #1
0
def test_flatten_unflatten():
    # build three sets (x,y,z)
    sx = set([point(1.0, 1.0), point(2.0, 1.0), point(3.0, 2.0)])
    sy = set([point(0.0, 1.0), point(3.0, 2.0)])
    sz = set([point(1.0, 1.0), point(2.0, 3.0)])

    # build a collection
    c = collection([sx, sy, sz])

    # flatten and unflatten
    from mystic.math.discrete import flatten, unflatten
    d = unflatten(flatten(c), c.pts)

    # check if the same
    assert c.npts == d.npts
    assert c.weights == d.weights
    assert c.positions == d.positions

    # flatten() and load(...)
    e = collection().load(c.flatten(), c.pts)

    # check if the same
    assert c.npts == e.npts
    assert c.weights == e.weights
    assert c.positions == e.positions

    # decompose and compose
    from mystic.math.discrete import decompose, compose
    b = compose(*decompose(c))

    # check if the same
    assert c.npts == b.npts
    assert c.weights == b.weights
    assert c.positions == b.positions
    return
예제 #2
0
def test_flatten_unflatten():
  # build three sets (x,y,z)
  sx = set([point(1.0,1.0), point(2.0,1.0), point(3.0,2.0)])
  sy = set([point(0.0,1.0), point(3.0,2.0)])
  sz = set([point(1.0,1.0), point(2.0,3.0)])

  # build a collection
  c = collection([sx,sy,sz])

  # flatten and unflatten
  from mystic.math.discrete import flatten, unflatten
  d = unflatten(flatten(c), c.pts)

  # check if the same
  assert c.npts == d.npts
  assert c.weights == d.weights
  assert c.positions == d.positions

  # flatten() and load(...)
  e = collection().load(c.flatten(), c.pts)

  # check if the same
  assert c.npts == e.npts
  assert c.weights == e.weights
  assert c.positions == e.positions

  # decompose and compose
  from mystic.math.discrete import decompose, compose
  b = compose(*decompose(c))

  # check if the same
  assert c.npts == b.npts
  assert c.weights == b.weights
  assert c.positions == b.positions
  return