1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/andy-upp-tensor-calcu-lib

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
test_02.py 1.9 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
andy-upp Отправлено 11.08.2020 21:33 7a22df3
import traceback
import numpy as np
import easynn as nn
import easynn_golden as golden
import easynn_cpp as cpp
def random_args(*args):
return {k: np.random.random() for k in args}
def is_same(p, n, *args):
e0 = p.compile(cpp.Builder())
e1 = p.compile(golden.Builder())
nkwargs = [random_args(*args) for i in range(n)]
return all([np.allclose(e0(**nkwargs[i]), e1(**nkwargs[i])) for i in range(n)])
def grade_Q1():
x = nn.Input("x")
return is_same(x, 1, "x")
def grade_Q2():
c = nn.Const(np.random.random())
return is_same(c, 1)
def grade_Q3():
x = nn.Input("x")
c = nn.Const(np.random.random())
y = x+c
return is_same(y, 1, "x")
def grade_Q4():
x = nn.Input("x")
c = nn.Const(np.random.random())
y = x*c
return is_same(y, 1, "x")
def grade_Q5():
x = nn.Input("x")
y = nn.Input("y")
z = x+y
return is_same(z, 1, "x", "y")
def grade_Q6():
x = nn.Input("x")
y = nn.Input("y")
z = x*y
return is_same(z, 1, "x", "y")
def grade_Q7():
x = nn.Input("x")
y = nn.Input("y")
z = nn.Input("z")
r = x+y*z
return is_same(r, 1, "x", "y", "z")
def grade_Q8():
x = nn.Input("x")
y = nn.Input("y")
z = nn.Input("z")
r = (x-y)*z
return is_same(r, 1, "x", "y", "z")
def grade_Q9():
x = nn.Input("x")
y = nn.Input("y")
c = nn.Const(np.random.random())
z = x*y-x*c-y*c+c*c
return is_same(z, 10, "x", "y")
def grade_Q10():
x = nn.Input("x")
y = nn.Input("y")
c = nn.Const(np.random.random())
z = x*y-x*c-y*c+c*c
return is_same(z, 10, "x", "y")
grade = 0
for q in range(1, 11):
func = globals()["grade_Q%d" % q]
try:
if func():
grade += 1
else:
print("============Q%d failed!============\n" % q)
except Exception as e:
print("============Q%d failed!============" % q)
print(traceback.format_exc())
print("Total questions passed: %d" % grade)

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/andy-upp-tensor-calcu-lib.git
git@api.gitlife.ru:oschina-mirror/andy-upp-tensor-calcu-lib.git
oschina-mirror
andy-upp-tensor-calcu-lib
andy-upp-tensor-calcu-lib
master