You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_array_creations.py 36 kB

5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. # Copyright 2020-2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """unit tests for numpy array operations"""
  16. import pytest
  17. import numpy as onp
  18. import mindspore.numpy as mnp
  19. from mindspore import context
  20. from .utils import rand_int, rand_bool, match_array, match_res, match_meta, \
  21. match_all_arrays, run_multi_test, to_tensor
  22. context.set_context(mode=context.PYNATIVE_MODE)
  23. class Cases():
  24. def __init__(self):
  25. self.all_shapes = [
  26. 1, 2, (1,), (2,), (1, 2, 3), [1], [2], [1, 2, 3]
  27. ]
  28. self.onp_dtypes = [onp.int32, 'int32', int,
  29. onp.float32, 'float32', float,
  30. onp.uint32, 'uint32',
  31. onp.bool_, 'bool', bool]
  32. self.mnp_dtypes = [mnp.int32, 'int32', int,
  33. mnp.float32, 'float32', float,
  34. mnp.uint32, 'uint32',
  35. mnp.bool_, 'bool', bool]
  36. self.array_sets = [1, 1.1, True, [1, 0, True], [1, 1.0, 2], (1,),
  37. [(1, 2, 3), (4, 5, 6)], onp.random.random( # pylint: disable=no-member
  38. (100, 100)).astype(onp.float32).tolist(),
  39. onp.random.random((100, 100)).astype(onp.bool).tolist()]
  40. self.arrs = [
  41. rand_int(2),
  42. rand_int(2, 3),
  43. rand_int(2, 3, 4),
  44. rand_int(2, 3, 4, 5),
  45. ]
  46. # scalars expanded across the 0th dimension
  47. self.scalars = [
  48. rand_int(),
  49. rand_int(1),
  50. rand_int(1, 1),
  51. rand_int(1, 1, 1),
  52. ]
  53. # arrays of the same size expanded across the 0th dimension
  54. self.expanded_arrs = [
  55. rand_int(2, 3),
  56. rand_int(1, 2, 3),
  57. rand_int(1, 1, 2, 3),
  58. rand_int(1, 1, 1, 2, 3),
  59. ]
  60. # arrays with dimensions of size 1
  61. self.nested_arrs = [
  62. rand_int(1),
  63. rand_int(1, 2),
  64. rand_int(3, 1, 8),
  65. rand_int(1, 3, 9, 1),
  66. ]
  67. # arrays which can be broadcast
  68. self.broadcastables = [
  69. rand_int(5),
  70. rand_int(6, 1),
  71. rand_int(7, 1, 5),
  72. rand_int(8, 1, 6, 1)
  73. ]
  74. # boolean arrays which can be broadcast
  75. self.bool_broadcastables = [
  76. rand_bool(),
  77. rand_bool(1),
  78. rand_bool(5),
  79. rand_bool(6, 1),
  80. rand_bool(7, 1, 5),
  81. rand_bool(8, 1, 6, 1),
  82. ]
  83. self.mnp_prototypes = [
  84. mnp.ones((2, 3, 4)),
  85. mnp.ones((1, 3, 1, 2, 5)),
  86. mnp.ones((2, 7, 1)),
  87. [mnp.ones(3), (1, 2, 3), mnp.ones(3), [4, 5, 6]],
  88. ([(1, 2), mnp.ones(2)], (mnp.ones(2), [3, 4])),
  89. ]
  90. self.onp_prototypes = [
  91. onp.ones((2, 3, 4)),
  92. onp.ones((1, 3, 1, 2, 5)),
  93. onp.ones((2, 7, 1)),
  94. [onp.ones(3), (1, 2, 3), onp.ones(3), [4, 5, 6]],
  95. ([(1, 2), onp.ones(2)], (onp.ones(2), [3, 4])),
  96. ]
  97. @pytest.mark.level1
  98. @pytest.mark.platform_arm_ascend_training
  99. @pytest.mark.platform_x86_ascend_training
  100. @pytest.mark.platform_x86_gpu_training
  101. @pytest.mark.platform_x86_cpu
  102. @pytest.mark.env_onecard
  103. def test_asarray():
  104. test_case = Cases()
  105. for array in test_case.array_sets:
  106. # Check for dtype matching
  107. actual = onp.asarray(array)
  108. expected = mnp.asarray(array).asnumpy()
  109. # Since we set float32/int32 as the default dtype in mindspore, we need
  110. # to make a conversion between numpy.asarray and mindspore.numpy.asarray
  111. if actual.dtype is onp.dtype('float64'):
  112. assert expected.dtype == onp.dtype('float32')
  113. elif actual.dtype is onp.dtype('int64'):
  114. assert expected.dtype == onp.dtype('int32')
  115. else:
  116. assert actual.dtype == expected.dtype
  117. match_array(actual, expected, error=7)
  118. for i in range(len(test_case.onp_dtypes)):
  119. actual = onp.asarray(array, test_case.onp_dtypes[i])
  120. expected = mnp.asarray(array, test_case.mnp_dtypes[i]).asnumpy()
  121. match_array(actual, expected, error=7)
  122. # Additional tests for nested tensor mixture
  123. mnp_input = [(mnp.ones(3,), mnp.ones(3)), [[1, 1, 1], (1, 1, 1)]]
  124. onp_input = [(onp.ones(3,), onp.ones(3)), [[1, 1, 1], (1, 1, 1)]]
  125. actual = onp.asarray(onp_input)
  126. expected = mnp.asarray(mnp_input).asnumpy()
  127. match_array(actual, expected, error=7)
  128. @pytest.mark.level1
  129. @pytest.mark.platform_arm_ascend_training
  130. @pytest.mark.platform_x86_ascend_training
  131. @pytest.mark.platform_x86_gpu_training
  132. @pytest.mark.platform_x86_cpu
  133. @pytest.mark.env_onecard
  134. def test_array():
  135. # array's function is very similar to asarray, so we mainly test the
  136. # `copy` argument.
  137. test_case = Cases()
  138. for array in test_case.array_sets:
  139. arr1 = mnp.asarray(array)
  140. arr2 = mnp.array(arr1, copy=False)
  141. arr3 = mnp.array(arr1)
  142. arr4 = mnp.asarray(array, dtype='int32')
  143. arr5 = mnp.asarray(arr4, dtype=mnp.int32)
  144. assert arr1 is arr2
  145. assert arr1 is not arr3
  146. assert arr4 is arr5
  147. # Additional tests for nested tensor/numpy_array mixture
  148. mnp_input = [(mnp.ones(3,), mnp.ones(3)), [[1, 1, 1], (1, 1, 1)]]
  149. onp_input = [(onp.ones(3,), onp.ones(3)), [[1, 1, 1], (1, 1, 1)]]
  150. actual = onp.array(onp_input)
  151. expected = mnp.array(mnp_input).asnumpy()
  152. match_array(actual, expected, error=7)
  153. @pytest.mark.level1
  154. @pytest.mark.platform_arm_ascend_training
  155. @pytest.mark.platform_x86_ascend_training
  156. @pytest.mark.platform_x86_gpu_training
  157. @pytest.mark.platform_x86_cpu
  158. @pytest.mark.env_onecard
  159. def test_asfarray():
  160. test_case = Cases()
  161. for array in test_case.array_sets:
  162. # Check for dtype matching
  163. actual = onp.asfarray(array)
  164. expected = mnp.asfarray(array).asnumpy()
  165. # Since we set float32/int32 as the default dtype in mindspore, we need
  166. # to make a conversion between numpy.asarray and mindspore.numpy.asarray
  167. if actual.dtype is onp.dtype('float64'):
  168. assert expected.dtype == onp.dtype('float32')
  169. else:
  170. assert actual.dtype == expected.dtype
  171. match_array(actual, expected, error=7)
  172. for i in range(len(test_case.onp_dtypes)):
  173. actual = onp.asfarray(array, test_case.onp_dtypes[i])
  174. expected = mnp.asfarray(array, test_case.mnp_dtypes[i]).asnumpy()
  175. match_array(actual, expected, error=7)
  176. # Additional tests for nested tensor/numpy_array mixture
  177. mnp_input = [(mnp.ones(3,), mnp.ones(3)), [[1, 1, 1], (1, 1, 1)]]
  178. onp_input = [(onp.ones(3,), onp.ones(3)), [[1, 1, 1], (1, 1, 1)]]
  179. actual = onp.asfarray(onp_input)
  180. expected = mnp.asfarray(mnp_input).asnumpy()
  181. match_array(actual, expected, error=7)
  182. @pytest.mark.level1
  183. @pytest.mark.platform_arm_ascend_training
  184. @pytest.mark.platform_x86_ascend_training
  185. @pytest.mark.platform_x86_gpu_training
  186. @pytest.mark.platform_x86_cpu
  187. @pytest.mark.env_onecard
  188. def test_zeros():
  189. test_case = Cases()
  190. for shape in test_case.all_shapes:
  191. for i in range(len(test_case.onp_dtypes)):
  192. actual = onp.zeros(shape, test_case.onp_dtypes[i])
  193. expected = mnp.zeros(shape, test_case.mnp_dtypes[i]).asnumpy()
  194. match_array(actual, expected)
  195. actual = onp.zeros(shape)
  196. expected = mnp.zeros(shape).asnumpy()
  197. match_array(actual, expected)
  198. @pytest.mark.level1
  199. @pytest.mark.platform_arm_ascend_training
  200. @pytest.mark.platform_x86_ascend_training
  201. @pytest.mark.platform_x86_gpu_training
  202. @pytest.mark.platform_x86_cpu
  203. @pytest.mark.env_onecard
  204. def test_ones():
  205. test_case = Cases()
  206. for shape in test_case.all_shapes:
  207. for i in range(len(test_case.onp_dtypes)):
  208. actual = onp.ones(shape, test_case.onp_dtypes[i])
  209. expected = mnp.ones(shape, test_case.mnp_dtypes[i]).asnumpy()
  210. match_array(actual, expected)
  211. actual = onp.ones(shape)
  212. expected = mnp.ones(shape).asnumpy()
  213. match_array(actual, expected)
  214. @pytest.mark.level1
  215. @pytest.mark.platform_arm_ascend_training
  216. @pytest.mark.platform_x86_ascend_training
  217. @pytest.mark.platform_x86_gpu_training
  218. @pytest.mark.platform_x86_cpu
  219. @pytest.mark.env_onecard
  220. def test_full():
  221. actual = onp.full((2, 2), [1, 2])
  222. expected = mnp.full((2, 2), [1, 2]).asnumpy()
  223. match_array(actual, expected)
  224. actual = onp.full((2, 3), True)
  225. expected = mnp.full((2, 3), True).asnumpy()
  226. match_array(actual, expected)
  227. actual = onp.full((3, 4, 5), 7.5)
  228. expected = mnp.full((3, 4, 5), 7.5).asnumpy()
  229. match_array(actual, expected)
  230. @pytest.mark.level1
  231. @pytest.mark.platform_arm_ascend_training
  232. @pytest.mark.platform_x86_ascend_training
  233. @pytest.mark.platform_x86_gpu_training
  234. @pytest.mark.platform_x86_cpu
  235. @pytest.mark.env_onecard
  236. def test_eye():
  237. test_case = Cases()
  238. for i in range(len(test_case.onp_dtypes)):
  239. for m in range(1, 5):
  240. actual = onp.eye(m, dtype=test_case.onp_dtypes[i])
  241. expected = mnp.eye(m, dtype=test_case.mnp_dtypes[i]).asnumpy()
  242. match_array(actual, expected)
  243. for n in range(1, 5):
  244. for k in range(0, 5):
  245. actual = onp.eye(m, n, k, dtype=test_case.onp_dtypes[i])
  246. expected = mnp.eye(
  247. m, n, k, dtype=test_case.mnp_dtypes[i]).asnumpy()
  248. match_array(actual, expected)
  249. @pytest.mark.level1
  250. @pytest.mark.platform_arm_ascend_training
  251. @pytest.mark.platform_x86_ascend_training
  252. @pytest.mark.platform_x86_gpu_training
  253. @pytest.mark.platform_x86_cpu
  254. @pytest.mark.env_onecard
  255. def test_identity():
  256. test_case = Cases()
  257. for i in range(len(test_case.onp_dtypes)):
  258. for m in range(1, 5):
  259. actual = onp.identity(m, dtype=test_case.onp_dtypes[i])
  260. expected = mnp.identity(m, dtype=test_case.mnp_dtypes[i]).asnumpy()
  261. match_array(actual, expected)
  262. @pytest.mark.level1
  263. @pytest.mark.platform_arm_ascend_training
  264. @pytest.mark.platform_x86_ascend_training
  265. @pytest.mark.platform_x86_gpu_training
  266. @pytest.mark.platform_x86_cpu
  267. @pytest.mark.env_onecard
  268. def test_arange():
  269. actual = onp.arange(10)
  270. expected = mnp.arange(10).asnumpy()
  271. match_array(actual, expected)
  272. actual = onp.arange(0, 10)
  273. expected = mnp.arange(0, 10).asnumpy()
  274. match_array(actual, expected)
  275. actual = onp.arange(10, step=0.1)
  276. expected = mnp.arange(10, step=0.1).asnumpy()
  277. match_array(actual, expected, error=6)
  278. actual = onp.arange(0.1, 9.9)
  279. expected = mnp.arange(0.1, 9.9).asnumpy()
  280. match_array(actual, expected, error=6)
  281. @pytest.mark.level0
  282. @pytest.mark.platform_arm_ascend_training
  283. @pytest.mark.platform_x86_ascend_training
  284. @pytest.mark.platform_x86_gpu_training
  285. @pytest.mark.platform_x86_cpu
  286. @pytest.mark.env_onecard
  287. def test_linspace():
  288. actual = onp.linspace(2.0, 3.0, dtype=onp.float32)
  289. expected = mnp.linspace(2.0, 3.0).asnumpy()
  290. match_array(actual, expected, error=6)
  291. actual = onp.linspace(2.0, 3.0, num=5, dtype=onp.float32)
  292. expected = mnp.linspace(2.0, 3.0, num=5).asnumpy()
  293. match_array(actual, expected, error=6)
  294. actual = onp.linspace(
  295. 2.0, 3.0, num=5, endpoint=False, dtype=onp.float32)
  296. expected = mnp.linspace(2.0, 3.0, num=5, endpoint=False).asnumpy()
  297. match_array(actual, expected, error=6)
  298. actual = onp.linspace(2.0, 3.0, num=5, retstep=True, dtype=onp.float32)
  299. expected = mnp.linspace(2.0, 3.0, num=5, retstep=True)
  300. match_array(actual[0], expected[0].asnumpy())
  301. assert actual[1] == expected[1].asnumpy()
  302. actual = onp.linspace(2.0, [3, 4, 5], num=5,
  303. endpoint=False, dtype=onp.float32)
  304. expected = mnp.linspace(
  305. 2.0, [3, 4, 5], num=5, endpoint=False).asnumpy()
  306. match_array(actual, expected, error=6)
  307. actual = onp.linspace(2.0, [[3, 4, 5]], num=5, endpoint=False, axis=2)
  308. expected = mnp.linspace(2.0, [[3, 4, 5]], num=5, endpoint=False, axis=2).asnumpy()
  309. match_array(actual, expected, error=6)
  310. start = onp.random.random([2, 1, 4]).astype("float32")
  311. stop = onp.random.random([1, 5, 1]).astype("float32")
  312. actual = onp.linspace(start, stop, num=20, retstep=True,
  313. endpoint=False, dtype=onp.float32)
  314. expected = mnp.linspace(to_tensor(start), to_tensor(stop), num=20,
  315. retstep=True, endpoint=False)
  316. match_array(actual[0], expected[0].asnumpy(), error=6)
  317. match_array(actual[1], expected[1].asnumpy(), error=6)
  318. actual = onp.linspace(start, stop, num=20, retstep=True,
  319. endpoint=False, dtype=onp.int16)
  320. expected = mnp.linspace(to_tensor(start), to_tensor(stop), num=20,
  321. retstep=True, endpoint=False, dtype=mnp.int16)
  322. match_array(actual[0], expected[0].asnumpy(), error=6)
  323. match_array(actual[1], expected[1].asnumpy(), error=6)
  324. for axis in range(2):
  325. actual = onp.linspace(start, stop, num=20, retstep=False,
  326. endpoint=False, dtype=onp.float32, axis=axis)
  327. expected = mnp.linspace(to_tensor(start), to_tensor(stop), num=20,
  328. retstep=False, endpoint=False, dtype=mnp.float32, axis=axis)
  329. match_array(actual, expected.asnumpy(), error=6)
  330. @pytest.mark.level1
  331. @pytest.mark.platform_arm_ascend_training
  332. @pytest.mark.platform_x86_ascend_training
  333. @pytest.mark.platform_x86_gpu_training
  334. @pytest.mark.platform_x86_cpu
  335. @pytest.mark.env_onecard
  336. def test_logspace():
  337. actual = onp.logspace(2.0, 3.0, dtype=onp.float32)
  338. expected = mnp.logspace(2.0, 3.0).asnumpy()
  339. match_array(actual, expected, error=3)
  340. actual = onp.logspace(2.0, 3.0, num=5, dtype=onp.float32)
  341. expected = mnp.logspace(2.0, 3.0, num=5).asnumpy()
  342. match_array(actual, expected, error=3)
  343. actual = onp.logspace(
  344. 2.0, 3.0, num=5, endpoint=False, dtype=onp.float32)
  345. expected = mnp.logspace(2.0, 3.0, num=5, endpoint=False).asnumpy()
  346. match_array(actual, expected, error=3)
  347. actual = onp.logspace(2.0, [3, 4, 5], num=5, base=2,
  348. endpoint=False, dtype=onp.float32)
  349. expected = mnp.logspace(
  350. 2.0, [3, 4, 5], num=5, base=2, endpoint=False).asnumpy()
  351. match_array(actual, expected, error=3)
  352. @pytest.mark.level1
  353. @pytest.mark.platform_arm_ascend_training
  354. @pytest.mark.platform_x86_ascend_training
  355. @pytest.mark.platform_x86_gpu_training
  356. @pytest.mark.platform_x86_cpu
  357. @pytest.mark.env_onecard
  358. def test_empty():
  359. test_case = Cases()
  360. for shape in test_case.all_shapes:
  361. for mnp_dtype, onp_dtype in zip(test_case.mnp_dtypes,
  362. test_case.onp_dtypes):
  363. actual = mnp.empty(shape, mnp_dtype).asnumpy()
  364. expected = onp.empty(shape, onp_dtype)
  365. match_meta(actual, expected)
  366. @pytest.mark.level1
  367. @pytest.mark.platform_arm_ascend_training
  368. @pytest.mark.platform_x86_ascend_training
  369. @pytest.mark.platform_x86_gpu_training
  370. @pytest.mark.platform_x86_cpu
  371. @pytest.mark.env_onecard
  372. def test_empty_like():
  373. test_case = Cases()
  374. for mnp_proto, onp_proto in zip(test_case.mnp_prototypes, test_case.onp_prototypes):
  375. actual = mnp.empty_like(mnp_proto).asnumpy()
  376. expected = onp.empty_like(onp_proto)
  377. assert actual.shape == expected.shape
  378. for mnp_dtype, onp_dtype in zip(test_case.mnp_dtypes,
  379. test_case.onp_dtypes):
  380. actual = mnp.empty_like(mnp_proto, dtype=mnp_dtype).asnumpy()
  381. expected = onp.empty_like(onp_proto, dtype=onp_dtype)
  382. match_meta(actual, expected)
  383. def run_x_like(mnp_fn, onp_fn):
  384. test_case = Cases()
  385. for mnp_proto, onp_proto in zip(test_case.mnp_prototypes, test_case.onp_prototypes):
  386. actual = mnp_fn(mnp_proto).asnumpy()
  387. expected = onp_fn(onp_proto)
  388. match_array(actual, expected)
  389. for shape in test_case.all_shapes:
  390. actual = mnp_fn(mnp_proto, shape=shape).asnumpy()
  391. expected = onp_fn(onp_proto, shape=shape)
  392. match_array(actual, expected)
  393. for mnp_dtype, onp_dtype in zip(test_case.mnp_dtypes,
  394. test_case.onp_dtypes):
  395. actual = mnp_fn(mnp_proto, dtype=mnp_dtype).asnumpy()
  396. expected = onp_fn(onp_proto, dtype=onp_dtype)
  397. match_array(actual, expected)
  398. actual = mnp_fn(mnp_proto, dtype=mnp_dtype,
  399. shape=shape).asnumpy()
  400. expected = onp_fn(onp_proto, dtype=onp_dtype, shape=shape)
  401. match_array(actual, expected)
  402. @pytest.mark.level1
  403. @pytest.mark.platform_arm_ascend_training
  404. @pytest.mark.platform_x86_ascend_training
  405. @pytest.mark.platform_x86_gpu_training
  406. @pytest.mark.platform_x86_cpu
  407. @pytest.mark.env_onecard
  408. def test_ones_like():
  409. run_x_like(mnp.ones_like, onp.ones_like)
  410. @pytest.mark.level1
  411. @pytest.mark.platform_arm_ascend_training
  412. @pytest.mark.platform_x86_ascend_training
  413. @pytest.mark.platform_x86_gpu_training
  414. @pytest.mark.platform_x86_cpu
  415. @pytest.mark.env_onecard
  416. def test_zeros_like():
  417. run_x_like(mnp.zeros_like, onp.zeros_like)
  418. @pytest.mark.level1
  419. @pytest.mark.platform_arm_ascend_training
  420. @pytest.mark.platform_x86_ascend_training
  421. @pytest.mark.platform_x86_gpu_training
  422. @pytest.mark.platform_x86_cpu
  423. @pytest.mark.env_onecard
  424. def test_full_like():
  425. test_case = Cases()
  426. for mnp_proto, onp_proto in zip(test_case.mnp_prototypes, test_case.onp_prototypes):
  427. shape = onp.zeros_like(onp_proto).shape
  428. fill_value = rand_int()
  429. actual = mnp.full_like(mnp_proto, to_tensor(fill_value)).asnumpy()
  430. expected = onp.full_like(onp_proto, fill_value)
  431. match_array(actual, expected)
  432. for i in range(len(shape) - 1, 0, -1):
  433. fill_value = rand_int(*shape[i:])
  434. actual = mnp.full_like(mnp_proto, to_tensor(fill_value)).asnumpy()
  435. expected = onp.full_like(onp_proto, fill_value)
  436. match_array(actual, expected)
  437. fill_value = rand_int(1, *shape[i + 1:])
  438. actual = mnp.full_like(mnp_proto, to_tensor(fill_value)).asnumpy()
  439. expected = onp.full_like(onp_proto, fill_value)
  440. match_array(actual, expected)
  441. @pytest.mark.level1
  442. @pytest.mark.platform_arm_ascend_training
  443. @pytest.mark.platform_x86_ascend_training
  444. @pytest.mark.platform_x86_gpu_training
  445. @pytest.mark.platform_x86_cpu
  446. @pytest.mark.env_onecard
  447. def test_tri_triu_tril():
  448. x = mnp.ones((16, 32), dtype="bool")
  449. match_array(mnp.tril(x).asnumpy(), onp.tril(x.asnumpy()))
  450. match_array(mnp.tril(x, -1).asnumpy(), onp.tril(x.asnumpy(), -1))
  451. match_array(mnp.triu(x).asnumpy(), onp.triu(x.asnumpy()))
  452. match_array(mnp.triu(x, -1).asnumpy(), onp.triu(x.asnumpy(), -1))
  453. x = mnp.ones((64, 64), dtype="uint8")
  454. match_array(mnp.tril(x).asnumpy(), onp.tril(x.asnumpy()))
  455. match_array(mnp.tril(x, 25).asnumpy(), onp.tril(x.asnumpy(), 25))
  456. match_array(mnp.triu(x).asnumpy(), onp.triu(x.asnumpy()))
  457. match_array(mnp.triu(x, 25).asnumpy(), onp.triu(x.asnumpy(), 25))
  458. match_array(mnp.tri(64, 64).asnumpy(), onp.tri(64, 64))
  459. match_array(mnp.tri(64, 64, -10).asnumpy(), onp.tri(64, 64, -10))
  460. @pytest.mark.level1
  461. @pytest.mark.platform_x86_gpu_training
  462. @pytest.mark.platform_x86_cpu
  463. @pytest.mark.env_onecard
  464. def test_nancumsum():
  465. x = rand_int(2, 3, 4, 5)
  466. x[0][2][1][3] = onp.nan
  467. x[1][0][2][4] = onp.nan
  468. x[1][1][1][1] = onp.nan
  469. match_res(mnp.nancumsum, onp.nancumsum, x)
  470. match_res(mnp.nancumsum, onp.nancumsum, x, axis=-2)
  471. match_res(mnp.nancumsum, onp.nancumsum, x, axis=0)
  472. match_res(mnp.nancumsum, onp.nancumsum, x, axis=3)
  473. def mnp_diagonal(arr):
  474. return mnp.diagonal(arr, offset=2, axis1=-1, axis2=0)
  475. def onp_diagonal(arr):
  476. return onp.diagonal(arr, offset=2, axis1=-1, axis2=0)
  477. @pytest.mark.level1
  478. @pytest.mark.platform_arm_ascend_training
  479. @pytest.mark.platform_x86_ascend_training
  480. @pytest.mark.platform_x86_gpu_training
  481. @pytest.mark.platform_x86_cpu
  482. @pytest.mark.env_onecard
  483. def test_diagonal():
  484. arr = rand_int(3, 5)
  485. for i in [-1, 0, 2]:
  486. match_res(mnp.diagonal, onp.diagonal, arr, offset=i, axis1=0, axis2=1)
  487. match_res(mnp.diagonal, onp.diagonal, arr, offset=i, axis1=1, axis2=0)
  488. arr = rand_int(7, 4, 9)
  489. for i in [-1, 0, 2]:
  490. match_res(mnp.diagonal, onp.diagonal, arr, offset=i, axis1=0, axis2=-1)
  491. match_res(mnp.diagonal, onp.diagonal, arr, offset=i, axis1=-2, axis2=2)
  492. match_res(mnp.diagonal, onp.diagonal, arr,
  493. offset=i, axis1=-1, axis2=-2)
  494. def mnp_trace(arr):
  495. return mnp.trace(arr, offset=4, axis1=1, axis2=2)
  496. def onp_trace(arr):
  497. return onp.trace(arr, offset=4, axis1=1, axis2=2)
  498. @pytest.mark.level0
  499. @pytest.mark.platform_arm_ascend_training
  500. @pytest.mark.platform_x86_ascend_training
  501. @pytest.mark.platform_x86_gpu_training
  502. @pytest.mark.platform_x86_cpu
  503. @pytest.mark.env_onecard
  504. def test_trace():
  505. arr = rand_int(3, 5)
  506. match_res(mnp.trace, onp.trace, arr, offset=-1, axis1=0, axis2=1)
  507. arr = rand_int(7, 4, 9)
  508. match_res(mnp.trace, onp.trace, arr, offset=0, axis1=-2, axis2=2)
  509. def mnp_meshgrid(*xi):
  510. a = mnp.meshgrid(*xi)
  511. b = mnp.meshgrid(*xi, sparse=True)
  512. c = mnp.meshgrid(*xi, indexing='ij')
  513. d = mnp.meshgrid(*xi, sparse=False, indexing='ij')
  514. return a, b, c, d
  515. def onp_meshgrid(*xi):
  516. a = onp.meshgrid(*xi)
  517. b = onp.meshgrid(*xi, sparse=True)
  518. c = onp.meshgrid(*xi, indexing='ij')
  519. d = onp.meshgrid(*xi, sparse=False, indexing='ij')
  520. return a, b, c, d
  521. @pytest.mark.level0
  522. @pytest.mark.platform_arm_ascend_training
  523. @pytest.mark.platform_x86_ascend_training
  524. @pytest.mark.platform_x86_gpu_training
  525. @pytest.mark.platform_x86_cpu
  526. @pytest.mark.env_onecard
  527. def test_meshgrid():
  528. xi = (onp.full(3, 2), onp.full(1, 5), onp.full(
  529. (2, 3), 9), onp.full((4, 5, 6), 7))
  530. for i in range(len(xi)):
  531. arrs = xi[i:]
  532. mnp_arrs = map(to_tensor, arrs)
  533. for mnp_res, onp_res in zip(mnp_meshgrid(*mnp_arrs), onp_meshgrid(*arrs)):
  534. match_all_arrays(mnp_res, onp_res)
  535. @pytest.mark.level1
  536. @pytest.mark.platform_arm_ascend_training
  537. @pytest.mark.platform_x86_ascend_training
  538. @pytest.mark.platform_x86_gpu_training
  539. @pytest.mark.platform_x86_cpu
  540. @pytest.mark.env_onecard
  541. def test_diagflat():
  542. arrs = [rand_int(2, 3)]
  543. for arr in arrs:
  544. for i in [-2, 0, 7]:
  545. match_res(mnp.diagflat, onp.diagflat, arr, k=i)
  546. @pytest.mark.level1
  547. @pytest.mark.platform_arm_ascend_training
  548. @pytest.mark.platform_x86_ascend_training
  549. @pytest.mark.platform_x86_gpu_training
  550. @pytest.mark.platform_x86_cpu
  551. @pytest.mark.env_onecard
  552. def test_diag():
  553. arrs = [rand_int(7), rand_int(5, 5), rand_int(3, 8), rand_int(9, 6)]
  554. for arr in arrs:
  555. for i in [-10, -5, -1, 0, 2, 5, 6, 10]:
  556. match_res(mnp.diag, onp.diag, arr, k=i)
  557. @pytest.mark.level1
  558. @pytest.mark.platform_arm_ascend_training
  559. @pytest.mark.platform_x86_ascend_training
  560. @pytest.mark.platform_x86_gpu_training
  561. @pytest.mark.platform_x86_cpu
  562. @pytest.mark.env_onecard
  563. def test_diag_indices():
  564. mnp_res = mnp.diag_indices(5, 7)
  565. onp_res = onp.diag_indices(5, 7)
  566. match_all_arrays(mnp_res, onp_res)
  567. def mnp_ix_(*args):
  568. return mnp.ix_(*args)
  569. def onp_ix_(*args):
  570. return onp.ix_(*args)
  571. @pytest.mark.level1
  572. @pytest.mark.platform_arm_ascend_training
  573. @pytest.mark.platform_x86_ascend_training
  574. @pytest.mark.platform_x86_gpu_training
  575. @pytest.mark.platform_x86_cpu
  576. @pytest.mark.env_onecard
  577. def test_ix_():
  578. arrs = [rand_int(i + 1) for i in range(10)]
  579. for i in range(10):
  580. test_arrs = arrs[:i + 1]
  581. match_res(mnp_ix_, onp_ix_, *test_arrs)
  582. def mnp_indices():
  583. a = mnp.indices((2, 3))
  584. b = mnp.indices((2, 3, 4), sparse=True)
  585. return a, b
  586. def onp_indices():
  587. a = onp.indices((2, 3))
  588. b = onp.indices((2, 3, 4), sparse=True)
  589. return a, b
  590. def test_indices():
  591. run_multi_test(mnp_indices, onp_indices, ())
  592. @pytest.mark.level1
  593. @pytest.mark.platform_arm_ascend_training
  594. @pytest.mark.platform_x86_ascend_training
  595. @pytest.mark.platform_x86_gpu_training
  596. @pytest.mark.platform_x86_cpu
  597. @pytest.mark.env_onecard
  598. def test_geomspace():
  599. start = onp.arange(1, 7).reshape(2, 3)
  600. end = [1000, 2000, 3000]
  601. match_array(mnp.geomspace(1, 256, num=9).asnumpy(),
  602. onp.geomspace(1, 256, num=9), error=1)
  603. match_array(mnp.geomspace(1, 256, num=8, endpoint=False).asnumpy(),
  604. onp.geomspace(1, 256, num=8, endpoint=False), error=1)
  605. match_array(mnp.geomspace(to_tensor(start), end, num=4).asnumpy(),
  606. onp.geomspace(start, end, num=4), error=1)
  607. match_array(mnp.geomspace(to_tensor(start), end, num=4, endpoint=False).asnumpy(),
  608. onp.geomspace(start, end, num=4, endpoint=False), error=1)
  609. match_array(mnp.geomspace(to_tensor(start), end, num=4, axis=-1).asnumpy(),
  610. onp.geomspace(start, end, num=4, axis=-1), error=1)
  611. match_array(mnp.geomspace(to_tensor(start), end, num=4, endpoint=False, axis=-1).asnumpy(),
  612. onp.geomspace(start, end, num=4, endpoint=False, axis=-1), error=1)
  613. start = onp.arange(1, 1 + 2*3*4*5).reshape(2, 3, 4, 5)
  614. end = [1000, 2000, 3000, 4000, 5000]
  615. for i in range(-5, 5):
  616. match_array(mnp.geomspace(to_tensor(start), end, num=4, axis=i).asnumpy(),
  617. onp.geomspace(start, end, num=4, axis=i), error=1)
  618. @pytest.mark.level1
  619. @pytest.mark.platform_arm_ascend_training
  620. @pytest.mark.platform_x86_ascend_training
  621. @pytest.mark.platform_x86_gpu_training
  622. @pytest.mark.platform_x86_cpu
  623. @pytest.mark.env_onecard
  624. def test_vander():
  625. arrs = [rand_int(i + 3) for i in range(3)]
  626. for i in range(3):
  627. mnp_vander = mnp.vander(to_tensor(arrs[i]))
  628. onp_vander = onp.vander(arrs[i])
  629. match_all_arrays(mnp_vander, onp_vander, error=1e-4)
  630. mnp_vander = mnp.vander(to_tensor(arrs[i]), N=2, increasing=True)
  631. onp_vander = onp.vander(arrs[i], N=2, increasing=True)
  632. match_all_arrays(mnp_vander, onp_vander, error=1e-4)
  633. @pytest.mark.level0
  634. @pytest.mark.platform_arm_ascend_training
  635. @pytest.mark.platform_x86_ascend_training
  636. @pytest.mark.platform_x86_gpu_training
  637. @pytest.mark.platform_x86_cpu
  638. @pytest.mark.env_onecard
  639. def test_tensor_fill():
  640. x = rand_int(2, 1, 4).astype(onp.float32)
  641. mnp_x = to_tensor(x)
  642. x.fill(6)
  643. match_all_arrays(mnp_x.fill(6), x)
  644. x.fill(None)
  645. match_all_arrays(mnp_x.fill(None), x)
  646. @pytest.mark.level1
  647. @pytest.mark.platform_arm_ascend_training
  648. @pytest.mark.platform_x86_ascend_training
  649. @pytest.mark.platform_x86_gpu_training
  650. @pytest.mark.platform_x86_cpu
  651. @pytest.mark.env_onecard
  652. def test_bartlett():
  653. for i in [-3, -1, 0, 1, 5, 6, 10, 15]:
  654. match_all_arrays(mnp.bartlett(i), onp.bartlett(i), error=3)
  655. @pytest.mark.level1
  656. @pytest.mark.platform_arm_ascend_training
  657. @pytest.mark.platform_x86_ascend_training
  658. @pytest.mark.platform_x86_gpu_training
  659. @pytest.mark.platform_x86_cpu
  660. @pytest.mark.env_onecard
  661. def test_blackman():
  662. for i in [-3, -1, 0, 1, 5, 6, 10, 15]:
  663. match_all_arrays(mnp.blackman(i), onp.blackman(i), error=3)
  664. @pytest.mark.level1
  665. @pytest.mark.platform_arm_ascend_training
  666. @pytest.mark.platform_x86_ascend_training
  667. @pytest.mark.platform_x86_gpu_training
  668. @pytest.mark.platform_x86_cpu
  669. @pytest.mark.env_onecard
  670. def test_hamming():
  671. for i in [-3, -1, 0, 1, 5, 6, 10, 15]:
  672. match_all_arrays(mnp.hamming(i), onp.hamming(i), error=3)
  673. @pytest.mark.level1
  674. @pytest.mark.platform_arm_ascend_training
  675. @pytest.mark.platform_x86_ascend_training
  676. @pytest.mark.platform_x86_gpu_training
  677. @pytest.mark.platform_x86_cpu
  678. @pytest.mark.env_onecard
  679. def test_hanning():
  680. for i in [-3, -1, 0, 1, 5, 6, 10, 15]:
  681. match_all_arrays(mnp.hanning(i), onp.hanning(i), error=3)
  682. @pytest.mark.level1
  683. @pytest.mark.platform_arm_ascend_training
  684. @pytest.mark.platform_x86_ascend_training
  685. @pytest.mark.platform_x86_gpu_training
  686. @pytest.mark.platform_x86_cpu
  687. @pytest.mark.env_onecard
  688. def test_triu_indices():
  689. m = rand_int().tolist()
  690. n = rand_int().tolist()
  691. k = rand_int().tolist()
  692. mnp_res = mnp.triu_indices(n, k, m)
  693. onp_res = onp.triu_indices(n, k, m)
  694. match_all_arrays(mnp_res, onp_res)
  695. @pytest.mark.level1
  696. @pytest.mark.platform_arm_ascend_training
  697. @pytest.mark.platform_x86_ascend_training
  698. @pytest.mark.platform_x86_gpu_training
  699. @pytest.mark.platform_x86_cpu
  700. @pytest.mark.env_onecard
  701. def test_tril_indices():
  702. m = rand_int().tolist()
  703. n = rand_int().tolist()
  704. k = rand_int().tolist()
  705. mnp_res = mnp.tril_indices(n, k, m)
  706. onp_res = onp.tril_indices(n, k, m)
  707. match_all_arrays(mnp_res, onp_res)
  708. @pytest.mark.level1
  709. @pytest.mark.platform_arm_ascend_training
  710. @pytest.mark.platform_x86_ascend_training
  711. @pytest.mark.platform_x86_gpu_training
  712. @pytest.mark.platform_x86_cpu
  713. @pytest.mark.env_onecard
  714. def test_triu_indices_from():
  715. m = int(rand_int().tolist())
  716. n = int(rand_int().tolist())
  717. t = mnp.asarray(rand_int(m, n).tolist())
  718. k = rand_int().tolist()
  719. mnp_res = mnp.triu_indices_from(t, k)
  720. onp_res = onp.triu_indices_from(t.asnumpy(), k)
  721. match_all_arrays(mnp_res, onp_res)
  722. @pytest.mark.level1
  723. @pytest.mark.platform_arm_ascend_training
  724. @pytest.mark.platform_x86_ascend_training
  725. @pytest.mark.platform_x86_gpu_training
  726. @pytest.mark.platform_x86_cpu
  727. @pytest.mark.env_onecard
  728. def test_tril_indices_from():
  729. m = int(rand_int().tolist())
  730. n = int(rand_int().tolist())
  731. t = mnp.asarray(rand_int(m, n).tolist())
  732. k = rand_int().tolist()
  733. mnp_res = mnp.tril_indices_from(t, k)
  734. onp_res = onp.tril_indices_from(t.asnumpy(), k)
  735. match_all_arrays(mnp_res, onp_res)
  736. @pytest.mark.level0
  737. @pytest.mark.platform_arm_ascend_training
  738. @pytest.mark.platform_x86_ascend_training
  739. @pytest.mark.platform_x86_gpu_training
  740. @pytest.mark.platform_x86_cpu
  741. @pytest.mark.env_onecard
  742. def test_histogram_bin_edges():
  743. x = onp.random.randint(-10, 10, 10)
  744. match_res(mnp.histogram_bin_edges, onp.histogram_bin_edges, x, onp.arange(5))
  745. match_res(mnp.histogram_bin_edges, onp.histogram_bin_edges, x, bins=(1, 2, 3), range=None, error=3)
  746. match_res(mnp.histogram_bin_edges, onp.histogram_bin_edges, x, bins=10, range=(2, 20), error=3)
  747. @pytest.mark.level1
  748. @pytest.mark.platform_arm_ascend_training
  749. @pytest.mark.platform_x86_ascend_training
  750. @pytest.mark.platform_x86_gpu_training
  751. @pytest.mark.platform_x86_cpu
  752. @pytest.mark.env_onecard
  753. def test_asarray_exception():
  754. with pytest.raises(TypeError):
  755. mnp.asarray({1, 2, 3})
  756. @pytest.mark.level1
  757. @pytest.mark.platform_arm_ascend_training
  758. @pytest.mark.platform_x86_ascend_training
  759. @pytest.mark.platform_x86_gpu_training
  760. @pytest.mark.platform_x86_cpu
  761. @pytest.mark.env_onecard
  762. def test_linspace_exception():
  763. with pytest.raises(TypeError):
  764. mnp.linspace(0, 1, num=2.5)
  765. @pytest.mark.level1
  766. @pytest.mark.platform_arm_ascend_training
  767. @pytest.mark.platform_x86_ascend_training
  768. @pytest.mark.platform_x86_gpu_training
  769. @pytest.mark.platform_x86_cpu
  770. @pytest.mark.env_onecard
  771. def test_empty_like_exception():
  772. with pytest.raises(ValueError):
  773. mnp.empty_like([[1, 2, 3], [4, 5]])
  774. @pytest.mark.level0
  775. @pytest.mark.platform_arm_ascend_training
  776. @pytest.mark.platform_x86_ascend_training
  777. @pytest.mark.platform_x86_gpu_training
  778. @pytest.mark.platform_x86_cpu
  779. @pytest.mark.env_onecard
  780. def test_pad():
  781. x_np = onp.random.random([2, 3, 4]).astype("float32")
  782. x_ms = mnp.asarray(x_np.tolist())
  783. # pad constant
  784. mnp_res = mnp.pad(x_ms, ((1, 1), (2, 2), (3, 4)))
  785. onp_res = onp.pad(x_np, ((1, 1), (2, 2), (3, 4)))
  786. match_all_arrays(mnp_res, onp_res, error=1e-5)
  787. mnp_res = mnp.pad(x_ms, ((1, 1), (2, 3), (4, 5)), constant_values=((3, 4), (5, 6), (7, 8)))
  788. onp_res = onp.pad(x_np, ((1, 1), (2, 3), (4, 5)), constant_values=((3, 4), (5, 6), (7, 8)))
  789. match_all_arrays(mnp_res, onp_res, error=1e-5)
  790. # pad statistic
  791. mnp_res = mnp.pad(x_ms, ((1, 1), (2, 2), (3, 4)), mode="mean", stat_length=((1, 2), (2, 10), (3, 4)))
  792. onp_res = onp.pad(x_np, ((1, 1), (2, 2), (3, 4)), mode="mean", stat_length=((1, 2), (2, 10), (3, 4)))
  793. match_all_arrays(mnp_res, onp_res, error=1e-5)
  794. # pad edge
  795. mnp_res = mnp.pad(x_ms, ((1, 1), (2, 2), (3, 4)), mode="edge")
  796. onp_res = onp.pad(x_np, ((1, 1), (2, 2), (3, 4)), mode="edge")
  797. match_all_arrays(mnp_res, onp_res, error=1e-5)
  798. # pad wrap
  799. mnp_res = mnp.pad(x_ms, ((1, 1), (2, 2), (3, 4)), mode="wrap")
  800. onp_res = onp.pad(x_np, ((1, 1), (2, 2), (3, 4)), mode="wrap")
  801. match_all_arrays(mnp_res, onp_res, error=1e-5)
  802. # pad linear_ramp
  803. mnp_res = mnp.pad(x_ms, ((1, 3), (5, 2), (3, 0)), mode="linear_ramp", end_values=((0, 10), (9, 1), (-10, 99)))
  804. onp_res = onp.pad(x_np, ((1, 3), (5, 2), (3, 0)), mode="linear_ramp", end_values=((0, 10), (9, 1), (-10, 99)))
  805. match_all_arrays(mnp_res, onp_res, error=1e-5)
  806. def pad_with_msfunc(vector, pad_width, iaxis, kwargs):
  807. pad_value = kwargs.get('padder', 10)
  808. vector[:pad_width[0]] = pad_value
  809. vector[-pad_width[1]:] = pad_value
  810. return vector
  811. def pad_with_npfunc(vector, pad_width, iaxis, kwargs):
  812. pad_value = kwargs.get('padder', 10)
  813. vector[:pad_width[0]] = pad_value
  814. vector[-pad_width[1]:] = pad_value
  815. @pytest.mark.level0
  816. @pytest.mark.platform_x86_gpu_training
  817. @pytest.mark.env_onecard
  818. def test_pad_gpu():
  819. x_np = onp.random.random([2, 1, 4, 3]).astype("float32")
  820. x_ms = mnp.asarray(x_np.tolist())
  821. # pad symmetric odd
  822. mnp_res = mnp.pad(x_ms, ((10, 3), (5, 2), (3, 0), (2, 6)), mode='symmetric', reflect_type='odd')
  823. onp_res = onp.pad(x_np, ((10, 3), (5, 2), (3, 0), (2, 6)), mode='symmetric', reflect_type='odd')
  824. match_all_arrays(mnp_res, onp_res, error=1e-5)
  825. # pad symmetric even
  826. mnp_res = mnp.pad(x_ms, ((10, 13), (5, 12), (3, 0), (2, 6)), mode='symmetric', reflect_type='even')
  827. onp_res = onp.pad(x_np, ((10, 13), (5, 12), (3, 0), (2, 6)), mode='symmetric', reflect_type='even')
  828. match_all_arrays(mnp_res, onp_res, error=1e-5)
  829. # pad reflect odd
  830. mnp_res = mnp.pad(x_ms, ((10, 3), (5, 2), (3, 0), (2, 6)), mode='reflect', reflect_type='odd')
  831. onp_res = onp.pad(x_np, ((10, 3), (5, 2), (3, 0), (2, 6)), mode='reflect', reflect_type='odd')
  832. match_all_arrays(mnp_res, onp_res, error=1e-5)
  833. # pad reflect even
  834. mnp_res = mnp.pad(x_ms, ((10, 13)), mode='reflect', reflect_type='even')
  835. onp_res = onp.pad(x_np, ((10, 13)), mode='reflect', reflect_type='even')
  836. match_all_arrays(mnp_res, onp_res, error=1e-5)
  837. # pad func
  838. x_np = onp.random.random([2, 4]).astype("float32")
  839. x_ms = mnp.asarray(x_np.tolist())
  840. mnp_res = mnp.pad(x_ms, ((5, 5)), mode=pad_with_msfunc, padder=99)
  841. onp_res = onp.pad(x_np, ((5, 5)), mode=pad_with_npfunc, padder=99)
  842. match_all_arrays(mnp_res, onp_res, error=1e-5)