本文整理汇总了Python中ufora.native.FORA类的典型用法代码示例。如果您正苦于以下问题:Python FORA类的具体用法?Python FORA怎么用?Python FORA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FORA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_joas
def test_joas(self):
#"test assertions about JOAs of particular axioms"
for item in self.vals_to_test:
jovt = self.getJOVT(item[0])
if len(item) == 4:
assert item[3] == "hasSideEffects", "illegal third argument to JOA"
expected_joa = FORANative.JudgmentOnAction(
FORANative.parseStringToJOR(item[1]),
FORANative.parseStringToJOR(item[2]),
True if len(item) == 4 and item[3] == "hasSideEffects" else False
)
computed_joa = self.joa(jovt)
if computed_joa:
self.assertTrue(
expected_joa.resultPart() == computed_joa.resultPart(),
"for JOVT %s should have had JOA resultPart: %s, but had: %s" \
% (jovt, expected_joa.resultPart(), computed_joa.resultPart())
)
#be a little more relaxed on the throwParts
self.assertTrue(
expected_joa.throwPart().covers(computed_joa.throwPart()),
"for JOVT %s: expected JOA throwPart %s does not cover computed JOA %s" \
% (jovt, expected_joa.throwPart(), computed_joa.throwPart())
)
if len(expected_joa.throwPart()) > 0:
self.assertTrue(
len(computed_joa.throwPart()) > 0,
"for JOVT %s: expected JOA %s throws, but computed JOA %s does not" \
%(jovt, expected_joa, computed_joa)
)
示例2: test_extractPausedComputationDuringVectorLoad
def test_extractPausedComputationDuringVectorLoad(self):
self.runtime = Runtime.getMainRuntime()
#self.dynamicOptimizer = self.runtime.dynamicOptimizer
vdm = FORANative.VectorDataManager(callbackScheduler, Setup.config().maxPageSizeInBytes)
context = ExecutionContext.ExecutionContext(
dataManager = vdm,
allowInterpreterTracing = False
)
context.evaluate(
FORA.extractImplValContainer(FORA.eval("fun() { [1,2,3].paged }")),
FORANative.ImplValContainer(FORANative.makeSymbol("Call"))
)
pagedVec = context.getFinishedResult().asResult.result
context.placeInEvaluationState(
FORANative.ImplValContainer(
(pagedVec,
FORANative.ImplValContainer(FORANative.makeSymbol("GetItem")),
FORANative.ImplValContainer(0))
)
)
vdm.unloadAllPossible()
context.resume()
self.assertTrue(context.isVectorLoad())
computation = context.extractPausedComputation()
self.assertEqual(len(computation.frames),1)
示例3: test_createInstance_2
def test_createInstance_2(self):
classIvc = FORA.eval(
"""let C = class {
member y;
member x;
};
C"""
).implVal_
x = 1
y = 2
res = ForaNative.simulateApply(
ForaNative.ImplValContainer(
(
classIvc,
makeSymbolIvc("CreateInstance"),
ForaNative.ImplValContainer(y),
ForaNative.ImplValContainer(x),
)
)
)
self.assertIsNotNone(res)
computed_x = ForaNative.simulateApply(
ForaNative.ImplValContainer((res, self.Symbol_member, makeSymbolIvc("x")))
)
self.assertEqual(computed_x, ForaNative.ImplValContainer(x))
示例4: getCacheRequestComputationResult
def getCacheRequestComputationResult(cacheCallElement):
bucketname = cacheCallElement[1].pyvalOrNone
keyname = cacheCallElement[2].pyvalOrNone
if not isinstance(bucketname, str) or not isinstance(keyname, str):
return ForaNative.ComputationResult.Exception(
ForaNative.ImplValContainer("Badly formed S3 dataset request: %s" % cacheCallElement)
)
s3Interface = getCurrentS3Interface()
if s3Interface.keyExists(bucketname, keyname):
keysAndSizesMatching = [(keyname, s3Interface.getKeySize(bucketname, keyname))]
else:
keysAndSizesMatching = s3Interface.listKeysWithPrefix(bucketname, keyname + "_")
indicesKeysAndSizes = []
for key, size, mtime in keysAndSizesMatching:
try:
index = int(key[len(keyname)+1:])
indicesKeysAndSizes.append((index, key, size))
except ValueError:
pass
keysAndSizesMatching = [(key, size) for _, key, size in sorted(indicesKeysAndSizes)]
if not keysAndSizesMatching:
return ForaNative.ComputationResult.Exception(
ForaNative.ImplValContainer("No keys matching %s/%s using %s" % (
bucketname,
keyname,
s3Interface
))
)
wholeVectorIVC = ForaNative.getEmptyVector()
for key, size in keysAndSizesMatching:
CHUNK_SIZE = 10 * 1024 * 1024
chunks = getAppropriateChunksForSize(size, CHUNK_SIZE)
for lowIndex, highIndex in chunks:
externalDatasetDesc = ForaNative.ExternalDatasetDescriptor.S3Dataset(
bucketname,
key,
lowIndex,
highIndex
)
vectorDataId = ForaNative.VectorDataID.External(externalDatasetDesc)
vectorIVC = ForaNative.createFORAFreeBinaryVector(vectorDataId, highIndex - lowIndex)
wholeVectorIVC = ForaNative.concatenateVectors(wholeVectorIVC, vectorIVC)
return ForaNative.ComputationResult.Result(wholeVectorIVC, ForaNative.ImplValContainer())
示例5: testMatchStructureCantMatchTooSmallTuple
def testMatchStructureCantMatchTooSmallTuple(self):
runtime = Runtime.getMainRuntime()
axioms = runtime.getAxioms()
jov = FORANative.parseStringToJOV("((1,2,3),`StructureMatch,((nothing, false), (nothing, false), (nothing, false), (nothing, false)))")
axiom = axioms.getAxiomByJOVT(runtime.getTypedForaCompiler(), jov.asTuple.jov)
self.assertTrue(list(axiom.asNative.resultSignature.resultPart().vals) == [FORANative.parseStringToJOV("nothing")])
示例6: test_vectorOfPagedVectorApplyWithDropping
def test_vectorOfPagedVectorApplyWithDropping(self):
self.desirePublisher.desireNumberOfWorkers(3, blocking=True)
expr = FORA.extractImplValContainer(
FORA.eval(
"""fun() {
let v =
Vector.range(20).apply(fun(ix) {
Vector.range(1250000.0+ix).paged
}).paged
let lookup = fun(ix) { v[ix] }
Vector.range(100).apply(fun(ix) { sum(0, 10**8); cached(lookup(ix)) })
v
}"""
)
)
computation1 = self.gateway.requestComputation(
makeComputationDefinitionFromIVCs(
expr,
ForaNative.makeSymbol("Call")
)
)
try:
response = self.gateway.finalResponses.get(timeout=60.0)
except Queue.Empty:
response = None
self.assertTrue(response is not None, response)
self.gateway.deprioritizeComputation(computation1)
self.desirePublisher.desireNumberOfWorkers(2, blocking=True)
expr2 = FORA.extractImplValContainer(
FORA.eval(
"""fun() {
let res = 0
for ix in sequence(10)
res = res + Vector.range(12500000+ix).sum()
return res
}"""
)
)
computation2 = self.gateway.requestComputation(
makeComputationDefinitionFromIVCs(
expr2,
ForaNative.makeSymbol("Call")
)
)
try:
response = self.gateway.finalResponses.get(timeout=60.0)
except Queue.Empty:
response = None
self.assertTrue(response is not None)
self.assertTrue(response[1].isResult())
self.gateway.deprioritizeComputation(computation2)
示例7: test_resolveAxiomDirectly_VeryLongComputation
def test_resolveAxiomDirectly_VeryLongComputation(self):
vectorIVC = FORA.extractImplValContainer(FORA.eval("[]"))
jov = ForaNative.parseStringToJOV(("({Vector([])}, `append, 2)"))
joa = self.axioms.resolveAxiomDirectly(self.compiler, jov.getTuple())
self.assertEqual(len(joa.throwPart()),0)
self.assertEqual(len(joa.resultPart()),1)
result = joa.resultPart()[0]
self.assertEqual(result, ForaNative.parseStringToJOV("{Vector([{Int64}])}"))
示例8: test_sortManySmallVectors
def test_sortManySmallVectors(self):
self.desirePublisher.desireNumberOfWorkers(4, blocking=True)
expr = FORA.extractImplValContainer(
FORA.eval(
"""fun() {
let shouldAllBeTrue =
Vector.range(20, fun(o) {
sorting.isSorted(
sort(Vector.range(50000 + o, fun(x) { x / 10 }))
)
});
for s in shouldAllBeTrue {
if (not s)
return false
}
return true
}"""
)
)
response = self.evaluateWithGateway(
makeComputationDefinitionFromIVCs(
expr,
ForaNative.makeSymbol("Call")
)
)
self.assertTrue(response[1].isResult())
self.assertTrue(response[1].asResult.result.pyval == True, response[1].asResult.result.pyval)
示例9: reasonAboutExpression
def reasonAboutExpression(self, expression, **variableJudgments):
reasoner = FORANative.SimpleForwardReasoner(self.compiler, self.axioms, False)
keys = sorted(list(variableJudgments.keys()))
functionText = "fun(" + ",".join(['_'] + keys) + ") { " + expression + " }"
frame = reasoner.reason(
makeJovt(
FORANative.parseStringToJOV(functionText),
*[FORANative.parseStringToJOV(variableJudgments[k]) for k in keys]
)
)
self.dumpReasonerSummary(reasoner, frame)
return frame
示例10: test_manyDuplicateCachecallsAndAdding
def test_manyDuplicateCachecallsAndAdding(self):
self.desirePublisher.desireNumberOfWorkers(2, blocking=True)
expr = FORA.extractImplValContainer(
FORA.eval(
"""fun() {
Vector.range(20).papply(fun(x) {
x + cached(sum(0,10**11))[0]
})
}"""
)
)
computationId = self.gateway.requestComputation(
makeComputationDefinitionFromIVCs(
expr,
ForaNative.makeSymbol("Call")
)
)
time.sleep(5)
self.desirePublisher.desireNumberOfWorkers(4, blocking=True)
try:
response = self.gateway.finalResponses.get(timeout=240.0)
except Queue.Empty:
response = None
self.assertTrue(response is not None)
self.assertTrue(response[1].isResult())
self.gateway.deprioritizeComputation(computationId)
示例11: test_expensive_brownian
def test_expensive_brownian(self):
self.desirePublisher.desireNumberOfWorkers(2, blocking=True)
expr = FORA.extractImplValContainer(
FORA.eval(
"""fun() {
let brownian = fun(x,t) {
if (t == 0)
return sum(0.0, x * 10.0**7.0)
else
{
let (l,r) = cached(brownian(x - 1, t - 1), brownian(x + 1, t - 1));
return sum(0.0, x * 10.0**7.0) + l + r
}
}
brownian(0, 5)
}"""
)
)
response = self.evaluateWithGateway(
makeComputationDefinitionFromIVCs(
expr,
ForaNative.makeSymbol("Call")
)
)
self.assertTrue(response[1].isResult())
示例12: test_TypedFora_Layout_UsingCompiler
def test_TypedFora_Layout_UsingCompiler(self):
layoutStyles = [
TypedFora.RefcountStyle.Pooled(),
TypedFora.RefcountStyle.AsValueUnowned(),
TypedFora.RefcountStyle.AsValueOwned()
]
jovs = [
ForaNative.parseStringToJOV("{String}"),
#a small union
ForaNative.parseStringToJOV("{Union([{String}, {Int64}])}"),
#a much bigger union
ForaNative.parseStringToJOV("{Union([{String}, {Int64}, {Float64}, nothing, ({Float64})])}"),
ForaNative.parseStringToJOV("'%s'" % aBigString),
ForaNative.parseStringToJOV("*")
]
for ls1 in layoutStyles:
for jov1 in jovs:
for ls2 in layoutStyles:
for jov2 in jovs:
if not (ls1.isAsValueOwned() and ls2.isAsValueUnowned()):
t1 = TypedFora.Type(jov1, ls1)
t2 = TypedFora.Type(jov2, ls2)
self.runSimpleEvaluation(t1, t2)
示例13: test_TypedFora_CreateTuple
def test_TypedFora_CreateTuple(self):
layoutStyles = [
TypedFora.RefcountStyle.Pooled(),
TypedFora.RefcountStyle.AsValueUnowned(),
TypedFora.RefcountStyle.AsValueOwned()
]
jovs = [
ForaNative.parseStringToJOV("{String}"),
ForaNative.parseStringToJOV("'a string'"),
ForaNative.parseStringToJOV("*")
]
aVal = ForaNative.ImplValContainer("a string")
allLayouts = []
for ls1 in layoutStyles:
for jov1 in jovs:
allLayouts.append(TypedFora.Type(jov1, ls1))
for t1 in allLayouts:
for t2 in allLayouts:
callable = self.generateTupleCallable([t1, t2], [False, False])
def validator(result):
return result == ForaNative.ImplValContainer((aVal, aVal))
self.runSimpleEvaluation(callable, [aVal, aVal], validator)
示例14: f
def test_cfgSplitting_5(self):
funString = "fun(f) { (f(1) + f(2)) + f(3) }"
cfg = self.parseStringToFunction(funString).toCFG(1)
steps = ForaNative.extractApplyStepsFromControlFlowGraph(cfg, None)
splits = ForaNative.splitControlFlowGraph(cfg, "block_0Let")
self.assertTrue(splits is not None)
示例15: size
def test_futures_tupleCallInContinuation_2(self):
text = "fun(x) { x = x + x; size((x, *x)) }"
cfg = self.parseStringToFunction(text).toCFG(1)
x = 1
xImplVal = ForaNative.ImplValContainer(x)
cfgWithFutures = ForaNative.CFGWithFutures.createCfgWithFutures(
cfg, "block_1Let", (xImplVal,))
cfgWithFutures.continueSimulation()
cfgWithFutures.continueSimulation()
self.assertEqual(cfgWithFutures.indicesOfSubmittableFutures(), [0])
x = x + x
cfgWithFutures.slotCompleted(
0, normalComputationResult(
ForaNative.ImplValContainer(x)
)
)
self.assertFalse(cfgWithFutures.hasResolvedToSimpleState())
self.assertEqual(cfgWithFutures.indicesOfSubmittableFutures(), [1])
self.assertComponentwiseEqual(
cfgWithFutures.submittableArgs(1).args.values,
[ForaNative.makeSymbol("size"), ForaNative.makeSymbol("Call"),
ForaNative.ImplValContainer((x, x))]
)