当前位置: 首页>>代码示例>>Python>>正文


Python Grid.unserialize方法代码示例

本文整理汇总了Python中pysgpp.Grid.unserialize方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.unserialize方法的具体用法?Python Grid.unserialize怎么用?Python Grid.unserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysgpp.Grid的用法示例。


在下文中一共展示了Grid.unserialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSerializationLinearBoudaryBoundingBox

# 需要导入模块: from pysgpp import Grid [as 别名]
# 或者: from pysgpp.Grid import unserialize [as 别名]
    def testSerializationLinearBoudaryBoundingBox(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createLinearBoundaryGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        boundingBox = factory.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        tempBound.leftBoundary = 0.0
        tempBound.rightBoundary = 100.0
        tempBound.bDirichletLeft = False;
        tempBound.bDirichletRight = False;
        boundingBox.setBoundary(0, tempBound)

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())
            
        boundingBox = newfac.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        self.assertEqual(0.0, tempBound.leftBoundary)
        self.assertEqual(100.0, tempBound.rightBoundary)
        self.assertEqual(False, tempBound.bDirichletLeft)
        self.assertEqual(False, tempBound.bDirichletRight)
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:34,代码来源:test_GridFactory.py

示例2: fromJson

# 需要导入模块: from pysgpp import Grid [as 别名]
# 或者: from pysgpp.Grid import unserialize [as 别名]
    def fromJson(cls, jsonObject):
        """
        Restores the ASGC object from the json object with its
        attributes.
        @param jsonObject: json object
        @return: the restored ASGC object
        """
        knowledge = ASGCKnowledge()

        # restore iteration
        key = '_ASGCKnowledge__iteration'
        if key in jsonObject:
            knowledge.setIteration(int(jsonObject[key]))

        # restore surpluses: {iteration: {qoi: {dtype: {t: <Grid>}}}}
        key = '_ASGCKnowledge__grids'
        if key in jsonObject:
            grids = {}
            for iteration, v1 in jsonObject[key].items():
                d1 = {}
                for qoi, gridString in v1.items():
                    # undo the hack that made it json compatible
                    gridString = gridString.replace('__', '\n')\
                                           .encode('utf8')
                    # compatibility with older poly basis type
                    gridString = gridString.replace('myPoly', 'poly')
                    # deserialize ...
                    grid = Grid.unserialize(gridString)
                    # ... and store it
                    d1[qoi] = grid
                grids[int(iteration)] = d1
            knowledge.setGrids(grids)

        # restore surpluses: {iteration: {qoi: {dtype: {t: <list float>}}}}
        key = '_ASGCKnowledge__alphas'
        if key in jsonObject:
            alphas = {}
            for iteration, v1 in jsonObject[key].items():
                d1 = {}
                for qoi, v2 in v1.items():
                    d2 = {}
                    for dtype, v3 in v2.items():
                        d3 = {}
                        for t, alpha in v3.items():
                            d3[float(t)] = DataVector(alpha)
                        d2[int(dtype)] = d3
                    d1[qoi] = d2
                alphas[int(iteration)] = d1
            knowledge.setAlphas(alphas)

        return knowledge
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:53,代码来源:ASGCKnowledge.py

示例3: testSerializationLinearBoudary

# 需要导入模块: from pysgpp import Grid [as 别名]
# 或者: from pysgpp.Grid import unserialize [as 别名]
    def testSerializationLinearBoudary(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createLinearBoundaryGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())        
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:19,代码来源:test_GridFactory.py

示例4: testSerializationLinearBoudaryWithLeaf

# 需要导入模块: from pysgpp import Grid [as 别名]
# 或者: from pysgpp.Grid import unserialize [as 别名]
    def testSerializationLinearBoudaryWithLeaf(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        srcLeaf = []
        factory = Grid.createLinearBoundaryGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        for i in xrange(factory.getStorage().size()):
            srcLeaf.append(factory.getStorage().get(i).isLeaf())

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())
        
        for i in xrange(factory.getStorage().size()):
            self.failUnlessEqual(newfac.getStorage().get(i).isLeaf(), srcLeaf[i])       
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:26,代码来源:test_GridFactory.py


注:本文中的pysgpp.Grid.unserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。