import example from example import add as a from example import sub as b print(example.add(4, 5)) print(example.sub(4, 5)) print(example.mul(4, 5)) print(a(5, 4)) print(b(5, 4))
import numpy as np import example A = np.array([[1, 2, 1], [2, 1, 0], [-1, 1, 2]]) B = 10 print(example.mul(A.astype(np.int), int(B))) print(example.mul(A.astype(np.float), float(B)))
import example from swimport.tests.resources import * b1 = example.mul(1, 2) assert_eq(b1, 2) assert_eq(example.mul(6, 89), 22) f, r = example.div(89, 6) assert_eq(f, 14) assert_eq(r, 5) assert_eq(example.inc(254), 255) assert_eq(example.dec(1), 0) assert_eq(example.round(215), 214)
import numpy as np import example print(example.mul(10.,20.)) print(example.mul(10 ,20.)) print(example.mul(10 ,20 ))
import numpy as np import example A = np.arange(5) B = np.arange(5) print(example.mul(A, B)) A = np.arange(25).reshape(5, 5) B = np.arange(25).reshape(5, 5) print(example.mul(A, B)) A = np.arange(125).reshape(5, 5, 5) B = np.arange(125).reshape(5, 5, 5) print(example.mul(A, B))
import example import numpy as np from swimport.tests.resources import * assert_eq( example.sum( np.array([[[1, 2], [2, 3]], [[3, 4], [4, 5]], [[1, 2], [2, 3]], [[3, 4], [4, 5]]])), 48) assert_eq(example.product(np.array([[[1, 2], [2, 3]], [[3, 4], [4, 5]]])), example.product(np.array([1, 2, 2, 3, 3, 4, 4, 5])), 2880) a = np.array([[1, 2], [3, 4]]) b = np.array([[5, 6, 7], [8, 9, 10]]) c = example.mul(a, b) assert_true(np.array_equal(c, a @ b))
print("Numbers::Three = " + str(test_enum)) print("compare with example::None : " + str(example.Num_None == test_enum)) x = demo1.num() y = demo2.num() print(str(x) + " + " + str(y) + " = " + str(example.add(x, y))) #print(str(x) + " + " + str(y) + " = " + str(example.add())) 导出的函数参数需要全部满足 #print(str(x) + " + " + str(y) + " = " + str(example.add1())) add1里面定义了arg1,arg2但是没有默认参数 print( str(x) + " + " + str(y) + " = " + str(example.add1(x=1, y=2))) #print(str(x) + " + " + str(y) + " = " + str(example.add(x = 1, y = 2))) add1定义了arg1,arg2,这里没有,所以不能这么用 print(str(x) + " + " + str(y) + " = " + str(example.add2())) #print(str(x) + " + " + str(y) + " = " + str(example.add3())) print(str(x) + " - " + str(y) + " = " + str(example.sub(x, y))) print( str(x) + " * " + str(y) + " = " + str(example.mul(example.B(), x, y))) print(str(x) + " / " + str(y) + " = " + str(example.div(x, y))) #print(str(x) + " / " + str(y) + " = " + str(example.div2(x, y))) pydemo = example.PyDemo() pydemo.name = "pydemo" pydemo.set_num(4) print(str(pydemo.name)) pydemo.print() except Exception as identifier: print("except : " + str(identifier))
def test_func(): print("mul() = {}".format(example.mul())) # 默认参数 int x, y = 1, 2 print("mul(12, 3) = {}".format(example.mul(12, 3))) # int x, y = 12, 3 print("mul(12.0, 2.0) = {}".format(example.mul( 12.0, 2.0))) # float x, y = 12.0, 2.0