rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
if not mode & 0200:
if stat.S_ISLNK(mode): return if not (mode & 0200):
def doFile(self, path): d = util.joinPaths(self.recipe.macros.destdir, path) mode = os.lstat(d)[stat.ST_MODE] if not mode & 0200: os.chmod(d, mode | 0200) f = file(d, 'r+') l = f.readlines() l = [x.replace('/lib/security/$ISA/', '') for x in l] f.seek(0) f.truncate(0) # we may have shrunk the file, avoid garbage f.writ...
if pkgfile.hasContents and (pkgfile.requires() & dep):
if pkgfile.hasContents:
def do(self): missingBuildRequires = set() missingBuildRequiresChoices = []
invariantinclusions = [ ('.*', 0400, stat.S_IFDIR)) ]
invariantinclusions = [ ('.*', 0400, stat.S_IFDIR), ]
def doFile(self, path): basename = os.path.basename(path) target = util.joinPaths(self.macros['initdir'], basename) if os.path.exists(self.macros['destdir'] + os.sep + target): raise policy.PolicyError( "Conflicting initscripts %s and %s installed" %( path, target)) util.mkdirChain(self.macros['destdir'] + os.sep + sel...
if not compRe.match(x))
if compRe.match(x))
def do(self): missingBuildRequires = set() missingBuildRequiresChoices = []
if missingCandidates == foundCandidates:
if foundCandidates and missingCandidates == foundCandidates:
def do(self): missingBuildRequires = set() missingBuildRequiresChoices = []
Now, suppose have an object and proxy it:
if adapter.__parent__ is None: adapter.__parent__ = parent return adapter
... def __init__(self, context):
>>> o = [] >>> p = ProxyFactory(o)
else: return adapter
... def __init__(self, context):
If we adapt it:
... def __init__(self, context):
>>> a = A(p)
class LocatingTrustedAdapterFactory(object): """Adapt an adapter factory to provide trusted and (locatable) adapters.
... def __init__(self, context):
the result is not a proxy:
Trusted adapters always adapt unproxied objects. If asked to adapt any proxied objects, it will unproxy them and then security-proxy the resulting adapter (S) unless the objects where not security-proxied before (N).
... def __init__(self, context):
>>> type(a).__name__ 'A'
Further locating trusted adapters provide a location for protected adapters only (S). If such a protected adapter itself does not provide ILocation it is wrapped within a location proxy and it parent will be set. If the adapter does provide ILocation and it's __parent__ is None, we set the __parent__ to the adapter's c...
... def __init__(self, context):
But the object it adapts still is:
see adapter.txt """ def __init__(self, factory): self.factory = factory self.__name__ = factory.__name__ self.__module__ = factory.__module__
... def __init__(self, context):
>>> type(a.context).__name__ '_Proxy'
def _customizeProtected(self, adapter, context): return assertLocation(adapter, context)
... def __init__(self, context):
Now, will we'll adapt our adapter factory to a trusted adapter factory:
def _customizeUnprotected(self, adapter, context): if (ILocation.providedBy(adapter) and adapter.__parent__ is None): adapter.__parent__ = context return adapter
... def __init__(self, context):
>>> TA = TrustedAdapterFactory(A)
def __call__(self, *args): for arg in args: if removeSecurityProxy(arg) is not arg: args = map(removeSecurityProxy, args) adapter = self.factory(*args) adapter = self._customizeProtected(adapter, args[0]) return ProxyFactory(adapter)
... def __init__(self, context):
and if we use it:
adapter = self.factory(*args) adapter = self._customizeUnprotected(adapter, args[0]) return adapter
... def __init__(self, context):
>>> a = TA(p)
... def __init__(self, context):
then the adapter is proxied:
class TrustedAdapterFactory(LocatingTrustedAdapterFactory): """Adapt an adapter factory to provide trusted adapters.
... def __init__(self, context):
>>> type(a).__name__ '_Proxy'
Trusted adapters always adapt unproxied objects. If asked to adapt any proxied objects, it will unproxy them and then security-proxy the resulting adapter unless the objects where not security-proxied before.
... def __init__(self, context):
And the object proxied is not. (We actually have to remove the adapter to get to the adapted object in this case.)
If the adapter does provide ILocation and it's __parent__ is None, we set the __parent__ to the adapter's context. """
... def __init__(self, context):
>>> a = removeSecurityProxy(a) >>> type(a.context).__name__ 'list'
def _customizeProtected(self, adapter, context): return self._customizeUnprotected(adapter, context)
... def __init__(self, context):
This works with multiple objects too:
... def __init__(self, context):
>>> class M(object): ... def __init__(self, *context): ... self.context = context
class LocatingUntrustedAdapterFactory(object): """Adapt an adapter factory to provide locatable untrusted adapters
... def __init__(self, context):
>>> TM = TrustedAdapterFactory(M)
Untrusted adapters always adapt proxied objects. If any permission other than zope.Public is required, untrusted adapters need a location in order that the local authentication mechanism can be inovked correctly.
... def __init__(self, *context):
>>> o2 = [] >>> o3 = []
If the adapter does not provide ILocation, we location proxy it and set the parent. If the adapter does provide ILocation and it's __parent__ is None, we set the __parent__ to the adapter's context only:
... def __init__(self, *context):
>>> a = TM(p, o2, o3) >>> type(a).__name__ '_Proxy' >>> a = removeSecurityProxy(a) >>> a.context[0] is o, a.context[1] is o2, a.context[2] is o3 (True, True, True) >>> a = TM(p, ProxyFactory(o2), ProxyFactory(o3)) >>> type(a).__name__ '_Proxy' >>> a = removeSecurityProxy(a) >>> a.context[0] is o, a.context[1] is o2, a...
see adapter.txt """
... def __init__(self, *context):
for arg in args: if removeSecurityProxy(arg) is not arg: args = map(removeSecurityProxy, args) adapter = self.factory(*args) if (ILocation.providedBy(adapter) and adapter.__parent__ is None): adapter.__parent__ = args[0] return ProxyFactory(adapter)
def __call__(self, *args): for arg in args: if removeSecurityProxy(arg) is not arg: args = map(removeSecurityProxy, args) adapter = self.factory(*args) if (ILocation.providedBy(adapter) and adapter.__parent__ is None): adapter.__parent__ = args[0] return ProxyFactory(adapter)
if (ILocation.providedBy(adapter) and adapter.__parent__ is None): adapter.__parent__ = args[0] return adapter
return assertLocation(adapter, args[0])
def __call__(self, *args): for arg in args: if removeSecurityProxy(arg) is not arg: args = map(removeSecurityProxy, args) adapter = self.factory(*args) if (ILocation.providedBy(adapter) and adapter.__parent__ is None): adapter.__parent__ = args[0] return ProxyFactory(adapter)
if isinstance(searchstring, list): searchstring = ' '.join(searchstring).strip()
def results(self, name): if not (name+'.search' in self.request): return None searchstring = self.request[name+'.searchstring'] if isinstance(searchstring, list): # Interpret as a string. # XXX This is a workaround for the fact that # SourceInputWidget generates a separate input field for # each principal source, so wh...
def test_suite(): return unittest.TestSuite(( DocTestSuite('zope.app.security.vocabulary'), ))
def test_suite(): return unittest.TestSuite(( DocTestSuite('zope.app.security.vocabulary'), ))
if __name__ == '__main__': unittest.main(defaultTest='test_suite')
class PermissionIdsVocabulary(SimpleVocabulary): """A vocabular of permission IDs. Term values are the permission ID strings except for 'zope.Public', which is the global permission CheckerPublic. Term titles are the permission ID strings except for 'zope.Public', which is shortened to 'Public'. Terms are sorted by ...
def test_suite(): return unittest.TestSuite(( DocTestSuite('zope.app.security.vocabulary'), ))
... return 1, 2, 3
... return ('1', 1), ('2', 2), ('3', 3)
... def getQueriables(self):
[dummy1, 1, 2, 3]
[(u'0', dummy1), (u'0.1', 1), (u'0.2', 2), (u'0.3', 3)]
... def getQueriables(self):
yield auth
yield unicode(i), auth
... def getQueriables(self):
for queriable in queriables.getQueriables(): yield queriable
for qid, queriable in queriables.getQueriables(): yield unicode(i)+'.'+unicode(qid), queriable
... def getQueriables(self):
def setIdOnActivation(event):
def setIdOnActivation(permission, event):
def setIdOnActivation(event): """Set the permission id upon registration activation. Let's see how this notifier can be used. First we need to create an event using the permission instance and a registration stub: >>> class Registration: ... def __init__(self, obj, name): ... self.component = obj ... ...
>>> setIdOnActivation(event)
>>> setIdOnActivation(perm1, event)
... def __init__(self, obj, name):
If the function is called and the component is not a local permission, nothing is done: >>> class Foo: ... id = 'no id' >>> foo = Foo() >>> event = registration.RegistrationActivatedEvent( ... Registration(foo, 'foo')) >>> setIdOnActivation(event) >>> foo.id 'no id'
... def __init__(self, obj, name):
perm = event.object.component if isinstance(perm, LocalPermission): perm.id = event.object.name
permission.id = event.object.name
... def __init__(self, obj, name):
def unsetIdOnDeactivation(event):
def unsetIdOnDeactivation(permission, event):
def unsetIdOnDeactivation(event): """Unset the permission id up registration deactivation. Let's see how this notifier can be used. First we need to create an event using the permission instance and a registration stub: >>> class Registration: ... def __init__(self, obj, name): ... self.component = obj .....
>>> unsetIdOnDeactivation(event)
>>> unsetIdOnDeactivation(perm1, event)
... def __init__(self, obj, name):
If the function is called and the component is not a local permission, nothing is done: >>> class Foo: ... id = 'foo' >>> foo = Foo() >>> event = registration.RegistrationDeactivatedEvent( ... Registration(foo, 'foo')) >>> unsetIdOnDeactivation(event) >>> foo.id 'foo'
... def __init__(self, obj, name):
perm = event.object.component if isinstance(perm, LocalPermission): perm.id = NULL_ID
permission.id = NULL_ID
... def __init__(self, obj, name):
>>> class DummyService3(DummyService2): ... def getQueriables(self): ... return ('4', 4), >>> dummy3 = DummyService3()
... def getQueriables(self):
[(u'0', dummy1), (u'0.1', 1), (u'0.2', 2), (u'0.3', 3)]
[(u'0', dummy1), (u'1.1', 1), (u'1.2', 2), (u'1.3', 3), (u'2.4', 4)]
... def getQueriables(self):
privaledges of the authenticated user.
privileges of the authenticated user.
def __init__(self, ownerous=1, authenticated=1): """ Two optional keyword arguments may be provided:
This function asserts that the adapter get location-proxied unless it does not provide ILocation itself. Further more the returned locatable adapter get its parent set unless its __parent__ attribute is not None.
This function asserts that the adapter get location-proxied if it doesn't provide ILocation itself. Further more the returned locatable adapter get its parent set if its __parent__ attribute is currently None.
def assertLocation(adapter, parent): """Assert locatable adapters. This function asserts that the adapter get location-proxied unless it does not provide ILocation itself. Further more the returned locatable adapter get its parent set unless its __parent__ attribute is not None. see adapter.txt """ # handle none-loca...
return True
return 1
def __nonzero__(self): """All IPy objects should evaluate to true in boolean context. Ordinarily, they do, but if handling a default route expressed as 0.0.0.0/0, the __len__() of the object becomes 0, which is used as the boolean value of the object. """ return True
return ((2L<<prefixlen-1)-1) << (_ipVersionToLen(version) - prefixlen)
if check_addr_prefixlen: return ((2L<<prefixlen-1)-1) << (_ipVersionToLen(version) - prefixlen) else: return 1
def _prefixlenToNetmask(prefixlen, version): """Return a mask of n bits as a long integer. From 'IP address conversion functions with the builtin socket module' by Alex Martelli http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66517 """ if prefixlen == 0: return 0 elif prefixlen < 0: raise ValueError, "Prefixle...
>>> print IP('127.0.0.1').strCompressed() 127.0.0.1 >>> print IP('2001:0658:022a:cafe:0200::1').strCompressed() 2001:658:22a:cafe:200::1
>>> IP('127.0.0.1').strCompressed() '127.0.0.1' >>> IP('2001:0658:022a:cafe:0200::1').strCompressed() '2001:658:22a:cafe:200::1' >>> IP('ffff:ffff:ffff:ffff:ffff:f:f:fffc/127').strCompressed() 'ffff:ffff:ffff:ffff:ffff:f:f:fffc/127'
def strCompressed(self, wantprefixlen = None): """Return a string representation in compressed format using '::' Notation.
return self.strNormal() + self._printPrefix(wantprefixlen)
return self.strNormal(0) + self._printPrefix(wantprefixlen)
def strCompressed(self, wantprefixlen = None): """Return a string representation in compressed format using '::' Notation.
while (num & 1) == 0:
while (num & 1) == 0 and bits != 0:
def _checkNetmask(netmask, masklen): """Checks if a netmask is expressable as e prefixlen.""" num = long(netmask) bits = masklen # remove zero bits at the end while (num & 1) == 0: num = num >> 1 bits -= 1 if bits == 0: break # now check if the rest consists only of ones while bits > 0: if (num & 1) == 0: raise Value...
Return the discriminance index if the tag, that is, the minimum
Return the discriminance index if the tag. Th discriminance index of the tag is defined as the minimum
def discriminance(self, tag): """ Return the discriminance index if the tag, that is, the minimum number of packages that would be eliminated by selecting only those tagged with this tag or only those not tagged with this tag. """ n = self.card(tag) tot = self.packageCount() return min(n, tot - n)
i = i + 1
def score_fun(x): return float((x-15)*(x-15))/x
class Version(object):
class Version(debian_support.Version, object):
def __str__(self): return "Could not parse version: "+self._version
p = re.compile(r'^(?:(?P<epoch>\d+):)?(?P<upstream>[A-Za-z0-9.+:~-]+?)' + r'(?:-(?P<debian>[A-Za-z0-9.~+]+))?$') m = p.match(str(version)) if m is None: raise VersionError(version) self.__attrs = m.groupdict() self.__attrs['full'] = str(version) full_version = property(lambda self: self.__attrs['full']) epoch = ...
else: d = {} for a in attrs[1:]: if a == attr: d[a] = value else: d[a] = getattr(self, a) version = "" if d['epoch'] and d['epoch'] != '0': version += d['epoch'] + ":" version += d['upstream_version'] if d['debian_version']: version += '-' + d['debian_version'] self.full_version = version full_version = property(la...
def __init__(self, version): p = re.compile(r'^(?:(?P<epoch>\d+):)?(?P<upstream>[A-Za-z0-9.+:~-]+?)' + r'(?:-(?P<debian>[A-Za-z0-9.~+]+))?$') m = p.match(str(version)) if m is None: raise VersionError(version) self.__attrs = m.groupdict() self.__attrs['full'] = str(version)
full_version = property(lambda self: self.version.full_version) debian_version = property(lambda self: self.version.debian_version) upstream_version = property(lambda self: self.version.upstream_version)
full_version = property(lambda self: self.version.full_version, lambda self, v: setattr(self.version, 'full_version', v)) epoch = property(lambda self: self.version.epoch, lambda self, v: setattr(self.version, 'epoch', v)) debian_version = property(lambda self: self.version.debian_version, lambda self, v: setattr(self....
def set_version(self, version): """Set the version of the last changelog block
versions = [] for block in self._blocks: versions.append[block.version] return versions
return [block.version for block in self._blocks]
def get_versions(self): """Returns a list of version objects that the package went through.""" versions = [] for block in self._blocks: versions.append[block.version] return versions
self.assertEqual((c1.full_version, c1.upstream_version, c1.debian_version), (c2.full_version, c2.upstream_version, c2.debian_version))
self.assertEqual((c1.full_version, c1.epoch, c1.upstream_version, c1.debian_version), (c2.full_version, c2.epoch, c2.upstream_version, c2.debian_version)) def test_magic_version_properties(self): c = Changelog(open('test_changelog').read()) c.debian_version = '2' self.assertEqual(c.debian_version, '2') self.assertEqu...
def test_set_version_with_string(self): c1 = Changelog(open('test_modify_changelog1').read()) c2 = Changelog(open('test_modify_changelog1').read())
def test_equality(self): v1 = Version('1:2.3.4-2') v2 = Version('1:2.3.4-2') self.assertEqual(v1, v2)
def test_version_updating(self): v = Version('1:1.4.1-1') v.debian_version = '2' self.assertEqual(v.debian_version, '2') self.assertEqual(v.full_version, '1:1.4.1-2') v.upstream_version = '1.4.2' self.assertEqual(v.upstream_version, '1.4.2') self.assertEqual(v.full_version, '1:1.4.2-2') v.epoch = '2' self.assertEqua...
def test_equality(self): v1 = Version('1:2.3.4-2') v2 = Version('1:2.3.4-2') self.assertEqual(v1, v2)
'\d\d:\d\d:\d\d \+\d\d\d\d( \(.*\))?)$')
'\d\d:\d\d:\d\d [-+]\d\d\d\d( \(.*\))?)$')
def __str__(self): block = "" if self.package() is None: raise ChangelogCreateError("Package not specified") block += self.package() + " " if self.version() is None: raise ChangelogCreateError("Version not specified") block += "(" + str(self.version()) + ") " if self.distributions() is None: raise ChangelogCreateError(...
cl.set_date('Sat, 16 Jul 2008 11:11:08 +0200')
cl.set_date('Sat, 16 Jul 2008 11:11:08 -0200')
def test_modify_changelog(self):
def testMultiply(self): "Test Epetra.MultiVector Multiply method" a = [self.numPyArray1,self.numPyArray2] emv0 = Epetra.MultiVector(self.map,2) emv1 = Epetra.MultiVector(self.map,a) emv2 = Epetra.MultiVector(self.map,a) self.assertEquals(emv0[:], 0.0) result = emv0('T','N',1.0,emv1,emv2)
def testMultiply(self): "Test Epetra.MultiVector Multiply method" a = [self.numPyArray1,self.numPyArray2] emv0 = Epetra.MultiVector(self.map,2) emv1 = Epetra.MultiVector(self.map,a) emv2 = Epetra.MultiVector(self.map,a) self.assertEquals(emv0[:], 0.0) result = emv0('T','N',1.0,emv1,emv2)
def testMultiply1(self): "Test Epetra.MultiVector Multiply method" n = 2 * self.comm.NumProc() map = Epetra.Map(n,0,self.comm) emv0 = Epetra.MultiVector(map,n) emv1 = Epetra.MultiVector(map,n) emv2 = Epetra.MultiVector(map,n) emv0.Random() emv1.Random() emv2.Random() result = emv0.Multiply(1.0,emv1,emv2,2.0) self.a...
# def testMultiply(self):
failure = 0
failures = 0
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...
Comm.Barrier()
comm.Barrier()
def main(): comm = Epetra.PyComm() if comm.MyPID() == 0: print Epetra.Version() nElem = 1000 map = Epetra.Map(nElem, 0, comm) x = Epetra.Vector(map) b = Epetra.Vector(map) b.Random() x.Update(2.0, b, 0.0) # x = 2*b xNorm = x.Norm2() bNorm = b.Norm2() if comm.MyPID() == 0: print "2 norm of x =", xNorm print...
elif Type == "Amesos_Pardiso": Solver = Amesos.Umfpack(Problem) elif Type == "Amesos_Taucs": Solver = Amesos.Umfpack(Problem)
def main(): Comm = Epetra.PyComm() args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0] NumGlobalRows = 10 Map = Epetra.Map(NumGlobalRows, 0, Comm) LHS_exact = Epetra.MultiVector(Map, 1) LHS = Epetra.MultiVector(Map, 1) RHS = Epetra.MultiVector(Map, 1) Matrix = Epetra.CrsMatrix(Epetra.Co...
print "Solver.Solve() return code = ", ierr
if Comm.MyPID() == 0: print " Solver.Solve() return code = ", ierr
def main(): Comm = Epetra.PyComm() args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0] NumGlobalRows = 10 Map = Epetra.Map(NumGlobalRows, 0, Comm) LHS_exact = Epetra.MultiVector(Map, 1) LHS = Epetra.MultiVector(Map, 1) RHS = Epetra.MultiVector(Map, 1) Matrix = Epetra.CrsMatrix(Epetra.Co...
return self.__label def Label(self):
def __str__(self): return self.__label
comm = Epetra.Pycomm()
comm = Epetra.PyComm()
def main(): n = 100 comm = Epetra.Pycomm() if comm.NumProc() != 1: print "This example is only serial, sorry" return map = Epetra.Map(n, 0, comm) op = MyOperator(map) print op.Label() lhs = Epetra.Vector(map) rhs = Epetra.Vector(map) rhs.PutScalar(1.0) lhs.PutScalar(0.0) Problem = Epetra.LinearProblem(op, lhs, ...
failures = main()
if numProc == 1: failures = main() else failure = 0
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...
if iAmRoot: print "I/O for BlockMap ... ",
if iAmRoot: print "I/O for Map ... ",
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...
(ierr, map2) = EpetraExt.MatrixMarketFileToBlockMap("map.mm", comm)
(ierr, map2) = EpetraExt.MatrixMarketFileToMap("map.mm", comm)
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...
(ierr, y) = EpetraExt.MatrixMarketFileToMultiVector("x.mm", map)
(ierr, y) = EpetraExt.MatrixMarketFileToMultiVector("x.mm", map2)
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...
A = Epetra.CrsMatrix(Epetra.Copy, map, 0)
A = Epetra.CrsMatrix(Epetra.Copy, map2, 0)
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...
(ierr, B) = EpetraExt.MatrixMarketFileToCrsMatrix("A.mm", map)
(ierr, B) = EpetraExt.MatrixMarketFileToCrsMatrix("A.mm", map2)
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...
print "pid = %d, lid = %d" % (self.comm.MyPID(), lid)
def testReplaceGlobalValue1(self): "Test Epetra.MultiVector ReplaceGlobalValue method" emv = Epetra.MultiVector(self.map,self.numPyArray) gid = 4 lid = self.map.LID(gid) print "pid = %d, lid = %d" % (self.comm.MyPID(), lid) self.assertEquals(emv[0,gid], 0.5) print emv emv.ReplaceGlobalValue(gid,0,5.0) print emv if lid ...
print emv emv.ReplaceGlobalValue(gid,0,5.0) print emv
result = emv.ReplaceGlobalValue(gid,0,5.0)
def testReplaceGlobalValue1(self): "Test Epetra.MultiVector ReplaceGlobalValue method" emv = Epetra.MultiVector(self.map,self.numPyArray) gid = 4 lid = self.map.LID(gid) print "pid = %d, lid = %d" % (self.comm.MyPID(), lid) self.assertEquals(emv[0,gid], 0.5) print emv emv.ReplaceGlobalValue(gid,0,5.0) print emv if lid ...
globalElements = range(color,self.globalSize,self.mySize) blockMap = mc.GenerateBlockMap(color) result = blockMap.MyGlobalElements() self.assertEqual(len(result), len(globalElements)) for i in range(len(result)): self.assertEqual(result[i],globalElements[i])
blockMap = mc.GenerateBlockMap(color) result = blockMap.MyGlobalElements() self.assertEqual(len(result), 1) self.assertEqual(result[0],self.map.GID(color))
def testGenerateBlockMap(self): "Test Epetra.MapColoring GenerateBlockMap method" colors = range(self.mySize) mc = Epetra.MapColoring(self.map,colors) for color in colors: globalElements = range(color,self.globalSize,self.mySize) blockMap = mc.GenerateBlockMap(color) result = blockMap.MyGlobalElements...
globalElements = range(color,self.globalSize,self.mySize) map = mc.GenerateMap(color) result = map.MyGlobalElements() self.assertEqual(len(result), len(globalElements)) for i in range(len(result)): self.assertEqual(result[i],globalElements[i])
map = mc.GenerateMap(color) result = map.MyGlobalElements() self.assertEqual(len(result), 1) self.assertEqual(result[0],self.map.GID(color))
def testGenerateMap(self): "Test Epetra.MapColoring GenerateMap method" colors = range(self.mySize) mc = Epetra.MapColoring(self.map,colors) for color in colors: globalElements = range(color,self.globalSize,self.mySize) map = mc.GenerateMap(color) result = map.MyGlobalElements() self.assertEqual(...
self.colMap = Epetra.Map(self.rowMap)
mge = list(self.rowMap.MyGlobalElements()) if self.indexBase not in mge: mge.insert(0,mge[0] -1) if self.size-1 not in mge: mge.append( mge[-1]+1) self.colMap = Epetra.Map(-1, mge, self.indexBase, self.comm)
def setUp(self): self.comm = Epetra.PyComm() self.numProc = self.comm.NumProc() self.mySize = 11 self.size = self.mySize * self.numProc self.indexBase = 0 self.rowMap = Epetra.Map(self.size, self.indexBase, self.comm) self.colMap = Epetra.Map(self.rowMap) self.nipr = ones(self.mySize) self.nip...
def fillGraph(self,graph):
def fillGraphGlobal(self,graph,complete=True):
def fillGraph(self,graph): n = self.size for lrid in range(graph.NumMyRows()): grid = graph.GRID(lrid) if grid == 0 : indices = [0,1] elif grid == n-1: indices = [n-2,n-1] else : indices = [grid-1,grid,grid+1] graph.InsertGlobalIndices(grid,indices) graph.FillComplete()
graph.FillComplete()
if complete: graph.FillComplete() def fillGraphLocal(self,graph,complete=True): n = self.size o = 0 if self.myPID > 0: o = 1 for lrid in range(graph.NumMyRows()): grid = graph.GRID(lrid) if grid == 0 : indices = [0,1] elif grid == n-1: indices = [lrid+o-1,lrid+o] else : indices = [lrid+o-1,lrid+o,lrid+o+...
def fillGraph(self,graph): n = self.size for lrid in range(graph.NumMyRows()): grid = graph.GRID(lrid) if grid == 0 : indices = [0,1] elif grid == n-1: indices = [n-2,n-1] else : indices = [grid-1,grid,grid+1] graph.InsertGlobalIndices(grid,indices) graph.FillComplete()
self.fillGraph(crsg)
self.fillGraphGlobal(crsg)
def testInsertGlobalIndices(self): "Test Epetra.CrsGraph InsertGlobalIndices method" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraph(crsg) # This calls crsg.InsertGlobalIndices() n = self.size for lrid in range(crsg.NumMyRows()): grid = crsg.GRID(lrid) if grid in (0,n-1): numIndices = 2 else: ...
def testRemoveGlobalIndices1(self): "Test Epetra.CrsGraph RemoveGlobalIndices method w/specified indices" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraphGlobal(crsg,False) grid = crsg.GRID(0) indices = crsg.ExtractGlobalRowCopy(grid) crsg.RemoveGlobalIndices(grid,indices[1:]) self.assertEqual(crsg.Nu...
#def testRemoveGlobalIndices(self):
self.fillGraph(crsg)
self.fillGraphGlobal(crsg)
def testExtractGlobalRowCopy(self): "Test Epetra.CrsGraph ExtractGlobalRowCopy method" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraph(crsg) n = crsg.GRID(self.mySize-1) indices = crsg.ExtractGlobalRowCopy(n) self.assertEqual(len(indices), 2 ) self.assertEqual(indices[0] , n-1) self.assertEqual(ind...
self.assertEqual(len(indices), 2 ) self.assertEqual(indices[0] , n-1) self.assertEqual(indices[1] , n )
ncol = 3 if n in (0,self.size-1): ncol -= 1 self.assertEqual(len(indices), ncol) self.assertEqual(indices[0] , n-1 ) self.assertEqual(indices[1] , n )
def testExtractGlobalRowCopy(self): "Test Epetra.CrsGraph ExtractGlobalRowCopy method" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraph(crsg) n = crsg.GRID(self.mySize-1) indices = crsg.ExtractGlobalRowCopy(n) self.assertEqual(len(indices), 2 ) self.assertEqual(indices[0] , n-1) self.assertEqual(ind...
self.fillGraph(crsg)
self.fillGraphGlobal(crsg)
def testExtractGlobalRowCopyBad(self): "Test Epetra.CrsGraph ExtractGlobalRowCopy method, bad index" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraph(crsg) self.assertRaises(ValueError, crsg.ExtractGlobalRowCopy, self.size)
self.fillGraph(crsg)
self.fillGraphGlobal(crsg)
def testExtractMyRowCopy(self): "Test Epetra.CrsGraph ExtractMyRowCopy method" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraph(crsg) n = self.mySize-1 indices = crsg.ExtractMyRowCopy(n) self.assertEqual(len(indices), 2 ) self.assertEqual(indices[0] , n-1) self.assertEqual(indices[1] , n )
self.assertEqual(len(indices), 2 ) self.assertEqual(indices[0] , n-1) self.assertEqual(indices[1] , n )
ncol = 3 if crsg.GRID(n) in (0,self.size-1): ncol -= 1 self.assertEqual(len(indices), ncol) self.assertEqual(indices[0] , n-1 ) self.assertEqual(indices[1] , n )
def testExtractMyRowCopy(self): "Test Epetra.CrsGraph ExtractMyRowCopy method" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraph(crsg) n = self.mySize-1 indices = crsg.ExtractMyRowCopy(n) self.assertEqual(len(indices), 2 ) self.assertEqual(indices[0] , n-1) self.assertEqual(indices[1] , n )
self.fillGraph(crsg)
self.fillGraphGlobal(crsg)
def testExtractMyRowCopyBad(self): "Test Epetra.CrsGraph ExtractMyRowCopy method, bad index" crsg = Epetra.CrsGraph(Epetra.Copy, self.rowMap, 3) self.fillGraph(crsg) self.assertRaises(ValueError, crsg.ExtractMyRowCopy, self.mySize)
eiv = Epetra.IntVector(self.map,list)
def testConstructor03(self): "Test Epetra.IntVector (BlockMap,bad-list) constructor" list = [0, 1.0, "e", "pi"] eiv = Epetra.IntVector(self.map,list) self.assertRaises(TypeError,Epetra.IntVector,self.map,list)
dict.update(parseExportFile(match.group(1).strip()))
tempDict = dict tempDict["include files"] = match.group(1).strip() makeSubstitutions(tempDict) for file in tempDict["include files"].split(): try: dict.update(parseExportFile(file)) except IOError: pass
def parseExportFile(filename): """Open filename, read in the text and return a dictionary of make variable names and values. If an include statement is found, this routine will be called recursively.""" lines = open(filename,"r").readlines() # Read in the lines of the Makefile lines = [s.split("#")[0] for s in lin...
self.__graph.InsertGlobalIndices(0,2,array([0,1])) for i in range(1,self.__size-1): self.__graph.InsertGlobalIndices(i,3,array([i-1,i,i+1])) self.__graph.InsertGlobalIndices(self.__size-1,2,array([self.__size-2, self.__size-1])) self.__graph.TransformToLocal()
for lrid in range(self.__graph.NumMyRows()): grid = self.__graph.GRID(lrid) if grid == 0 : indices = [0,1] elif grid == self.__size-1: indices = [grid-1,grid] else : indices = [grid-1,grid,grid+1] self.__graph.InsertGlobalIndices(grid,len(indices),indices) self.__graph.FillComplete()
def computeGraph(self): self.__graph = Epetra.CrsGraph(Epetra.Copy, self.__map, 3) self.__graph.InsertGlobalIndices(0,2,array([0,1])) for i in range(1,self.__size-1): self.__graph.InsertGlobalIndices(i,3,array([i-1,i,i+1])) self.__graph.InsertGlobalIndices(self.__size-1,2,array([self.__size-2, self.__size-1])) self.__g...
comm = Epetra.SerialComm()
comm = Epetra.PyComm()
def main(): # Set up the (serial) communicator comm = Epetra.SerialComm() myPID = comm.MyPID() numProc = comm.NumProc() # Get the problem size from the command line if (len(sys.argv) > 2): print "usage:", sys.argv[0], "problemSize" sys.exit(1) if (len(sys.argv) == 1): probSize = 11 else: probSize = int(sys.argv[1...
probSize = 11
probSize = 11 * comm.NumProc()
def main(): # Set up the (serial) communicator comm = Epetra.SerialComm() myPID = comm.MyPID() numProc = comm.NumProc() # Get the problem size from the command line if (len(sys.argv) > 2): print "usage:", sys.argv[0], "problemSize" sys.exit(1) if (len(sys.argv) == 1): probSize = 11 else: probSize = int(sys.argv[1...
print "probSize =", probSize
if myPID == 0: print "probSize =", probSize
def main(): # Set up the (serial) communicator comm = Epetra.SerialComm() myPID = comm.MyPID() numProc = comm.NumProc() # Get the problem size from the command line if (len(sys.argv) > 2): print "usage:", sys.argv[0], "problemSize" sys.exit(1) if (len(sys.argv) == 1): probSize = 11 else: probSize = int(sys.argv[1...
n = 1000
comm = Epetra.PyComm() n = 1000
def main(): # Defines a communicator (serial or parallel, depending on how Trilinos # was configured), and creates a matrix corresponding to a 1D Laplacian. # AT THIS MOMENT THE EXAMPLE IS ONLY SERIAL n = 1000 Space = ML.Space(n) Matrix = ML.PyMatrix(Space, Space) for i in Space.GetMyGlobalElements(): if i > 0: Matri...
if Comm.MyPID() == 0:
if comm.MyPID() == 0:
def main(): # Defines a communicator (serial or parallel, depending on how Trilinos # was configured), and creates a matrix corresponding to a 1D Laplacian. # AT THIS MOMENT THE EXAMPLE IS ONLY SERIAL n = 1000 Space = ML.Space(n) Matrix = ML.PyMatrix(Space, Space) for i in Space.GetMyGlobalElements(): if i > 0: Matri...
failures = main() else failure = 0
failures = main() else: failure = 0
def main(): failures = 0 tolerance = 1.0e-12 # Construct a vector x and populate with random values n = 10 * numProc map = Epetra.Map(n, 0, comm) x = Epetra.Vector(map) x.Random() # ==================================================== # # Write map to file "map.mm" in MatrixMarket format, # # read...