Tools.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. import os.path
  2. import struct
  3. import numpy as np
  4. def normalize(a):
  5. return(a/max(np.abs(a)))
  6. TAILONLY = 1
  7. BODYONLY = 2
  8. BODYANDTAIL = 3
  9. def loopnb(format,loopkind):
  10. nb = 0
  11. if loopkind == TAILONLY:
  12. if format == 64:
  13. nb = 1
  14. if format == 0 or format == 31:
  15. nb = 3
  16. if format == 15:
  17. nb = 7
  18. if format == 7:
  19. nb = 15
  20. if loopkind == BODYONLY:
  21. if format == 64:
  22. nb = 4
  23. if format == 0 or format == 31:
  24. nb = 8
  25. if format == 15:
  26. nb = 16
  27. if format == 7:
  28. nb = 32
  29. if loopkind == BODYANDTAIL:
  30. if format == 64:
  31. nb = 5
  32. if format == 0 or format == 31:
  33. nb = 11 # 9
  34. if format == 15:
  35. nb = 23 # 17
  36. if format == 7:
  37. nb = 47 # 33
  38. return(nb)
  39. # Tools to generate pattern files
  40. def createMissingDir(destPath):
  41. theDir=os.path.normpath(destPath)
  42. if not os.path.exists(theDir):
  43. os.makedirs(theDir)
  44. # Pack an array of boolean into uint32
  45. def packset(a):
  46. b = np.packbits(a)
  47. newSize = int(np.ceil(b.shape[0] / 4.0)) * 4
  48. c = np.copy(b)
  49. c.resize(newSize)
  50. #print(c)
  51. vecSize = round(newSize/4)
  52. c=c.reshape(vecSize,4)
  53. #print(c)
  54. r = np.zeros(vecSize)
  55. result = []
  56. for i in range(0,vecSize):
  57. #print(c[i,:])
  58. #print("%X %X %X %X" % (c[i,0],c[i,1],c[i,2],c[i,3]))
  59. d = (c[i,0] << 24) | (c[i,1] << 16) | (c[i,2] << 8) | c[i,3]
  60. result.append(np.uint32(d))
  61. return(result)
  62. def float_to_hex(f):
  63. """ Convert and x86 float to an ARM unsigned long int.
  64. Args:
  65. f (float): value to be converted
  66. Raises:
  67. Nothing
  68. Returns:
  69. str : representation of the hex value
  70. """
  71. return hex(struct.unpack('<I', struct.pack('<f', f))[0])
  72. def float64_to_hex(f):
  73. """ Convert and x86 float to an ARM unsigned long int.
  74. Args:
  75. f (float): value to be converted
  76. Raises:
  77. Nothing
  78. Returns:
  79. str : representation of the hex value
  80. """
  81. return hex(struct.unpack('<Q', struct.pack('<d', f))[0])
  82. def to_q63(v):
  83. r = int(round(v * 2**63))
  84. if (r > 0x07FFFFFFFFFFFFFFF):
  85. r = 0x07FFFFFFFFFFFFFFF
  86. if (r < -0x08000000000000000):
  87. r = -0x08000000000000000
  88. return ("0x%s" % format(struct.unpack('<Q', struct.pack('<q', r))[0],'016X'))
  89. def to_q31(v):
  90. r = int(round(v * 2**31))
  91. if (r > 0x07FFFFFFF):
  92. r = 0x07FFFFFFF
  93. if (r < -0x080000000):
  94. r = -0x080000000
  95. return ("0x%s" % format(struct.unpack('<I', struct.pack('<i', r))[0],'08X'))
  96. def to_q15(v):
  97. r = int(round(v * 2**15))
  98. if (r > 0x07FFF):
  99. r = 0x07FFF
  100. if (r < -0x08000):
  101. r = -0x08000
  102. return ("0x%s" % format(struct.unpack('<H', struct.pack('<h', r))[0],'04X'))
  103. def to_q7(v):
  104. r = int(round(v * 2**7))
  105. if (r > 0x07F):
  106. r = 0x07F
  107. if (r < -0x080):
  108. r = -0x080
  109. return ("0x%s" % format(struct.unpack('<B', struct.pack('<b', r))[0],'02X'))
  110. def s8(r):
  111. return ("0x%s" % format(struct.unpack('<B', struct.pack('<b', r))[0],'02X'))
  112. def s16(r):
  113. return ("0x%s" % format(struct.unpack('<H', struct.pack('<h', r))[0],'04X'))
  114. def s32(r):
  115. return ("0x%s" % format(struct.unpack('<I', struct.pack('<i', r))[0],'08X'))
  116. def u32(r):
  117. return ("0x%s" % format(struct.unpack('<I', struct.pack('<I', r))[0],'08X'))
  118. class Config:
  119. def __init__(self,patternDir,paramDir,ext):
  120. self._patternDir = "%s%s" % (patternDir,ext.upper())
  121. self._paramDir = "%s%s" % (paramDir,ext.upper())
  122. self._ext = ext
  123. createMissingDir(self._patternDir)
  124. createMissingDir(self._paramDir)
  125. def inputP(self,i,name=None):
  126. """ Path to a reference pattern from the ID
  127. Args:
  128. i (int): ID to the reference pattern
  129. Raises:
  130. Nothing
  131. Returns:
  132. str : path to the file where to generate the pattern data
  133. """
  134. if name:
  135. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,self._ext)))
  136. else:
  137. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,self._ext)))
  138. def inputS32P(self,i,name=None):
  139. """ Path to a reference pattern from the ID
  140. Args:
  141. i (int): ID to the reference pattern
  142. Raises:
  143. Nothing
  144. Returns:
  145. str : path to the file where to generate the pattern data
  146. """
  147. if name:
  148. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s32")))
  149. else:
  150. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"s32")))
  151. def inputS16P(self,i,name=None):
  152. """ Path to a reference pattern from the ID
  153. Args:
  154. i (int): ID to the reference pattern
  155. Raises:
  156. Nothing
  157. Returns:
  158. str : path to the file where to generate the pattern data
  159. """
  160. if name:
  161. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s16")))
  162. else:
  163. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"s16")))
  164. def inputS8P(self,i,name=None):
  165. """ Path to a reference pattern from the ID
  166. Args:
  167. i (int): ID to the reference pattern
  168. Raises:
  169. Nothing
  170. Returns:
  171. str : path to the file where to generate the pattern data
  172. """
  173. if name:
  174. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s8")))
  175. else:
  176. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"s8")))
  177. def inputF32P(self,i,name=None):
  178. """ Path to a reference pattern from the ID
  179. Args:
  180. i (int): ID to the reference pattern
  181. Raises:
  182. Nothing
  183. Returns:
  184. str : path to the file where to generate the pattern data
  185. """
  186. if name:
  187. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"f32")))
  188. else:
  189. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"f32")))
  190. def inputQ31P(self,i,name=None):
  191. """ Path to a reference pattern from the ID
  192. Args:
  193. i (int): ID to the reference pattern
  194. Raises:
  195. Nothing
  196. Returns:
  197. str : path to the file where to generate the pattern data
  198. """
  199. if name:
  200. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q31")))
  201. else:
  202. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"q31")))
  203. def inputQ15P(self,i,name=None):
  204. """ Path to a reference pattern from the ID
  205. Args:
  206. i (int): ID to the reference pattern
  207. Raises:
  208. Nothing
  209. Returns:
  210. str : path to the file where to generate the pattern data
  211. """
  212. if name:
  213. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q15")))
  214. else:
  215. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"q15")))
  216. def inputQ7P(self,i,name=None):
  217. """ Path to a reference pattern from the ID
  218. Args:
  219. i (int): ID to the reference pattern
  220. Raises:
  221. Nothing
  222. Returns:
  223. str : path to the file where to generate the pattern data
  224. """
  225. if name:
  226. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q7")))
  227. else:
  228. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"q7")))
  229. def inputU32P(self,i,name=None):
  230. """ Path to a reference pattern from the ID
  231. Args:
  232. i (int): ID to the reference pattern
  233. Raises:
  234. Nothing
  235. Returns:
  236. str : path to the file where to generate the pattern data
  237. """
  238. if name:
  239. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"u32")))
  240. else:
  241. return(os.path.join(self._patternDir,"Input%d_%s.txt" % (i,"u32")))
  242. def refP(self,i,name=None):
  243. """ Path to a reference pattern from the ID
  244. Args:
  245. i (int): ID to the reference pattern
  246. Raises:
  247. Nothing
  248. Returns:
  249. str : path to the file where to generate the pattern data
  250. """
  251. if name:
  252. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,self._ext)))
  253. else:
  254. return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,self._ext)))
  255. def refS8P(self,i,name=None):
  256. """ Path to a reference pattern from the ID
  257. Args:
  258. i (int): ID to the reference pattern
  259. Raises:
  260. Nothing
  261. Returns:
  262. str : path to the file where to generate the pattern data
  263. """
  264. if name:
  265. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s8")))
  266. else:
  267. return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"s8")))
  268. def refS16P(self,i,name=None):
  269. """ Path to a reference pattern from the ID
  270. Args:
  271. i (int): ID to the reference pattern
  272. Raises:
  273. Nothing
  274. Returns:
  275. str : path to the file where to generate the pattern data
  276. """
  277. if name:
  278. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s16")))
  279. else:
  280. return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"s16")))
  281. def refS32P(self,i,name=None):
  282. """ Path to a reference pattern from the ID
  283. Args:
  284. i (int): ID to the reference pattern
  285. Raises:
  286. Nothing
  287. Returns:
  288. str : path to the file where to generate the pattern data
  289. """
  290. if name:
  291. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"s32")))
  292. else:
  293. return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"s32")))
  294. def refQ63P(self,i,name=None):
  295. """ Path to a reference pattern from the ID
  296. Args:
  297. i (int): ID to the reference pattern
  298. Raises:
  299. Nothing
  300. Returns:
  301. str : path to the file where to generate the pattern data
  302. """
  303. if name:
  304. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q63")))
  305. else:
  306. return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"q63")))
  307. def refQ31P(self,i,name=None):
  308. """ Path to a reference pattern from the ID
  309. Args:
  310. i (int): ID to the reference pattern
  311. Raises:
  312. Nothing
  313. Returns:
  314. str : path to the file where to generate the pattern data
  315. """
  316. if name:
  317. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"q31")))
  318. else:
  319. return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"q31")))
  320. def refF32P(self,i,name=None):
  321. """ Path to a reference pattern from the ID
  322. Args:
  323. i (int): ID to the reference pattern
  324. Raises:
  325. Nothing
  326. Returns:
  327. str : path to the file where to generate the pattern data
  328. """
  329. if name:
  330. return(os.path.join(self._patternDir,"%s%d_%s.txt" % (name,i,"f32")))
  331. else:
  332. return(os.path.join(self._patternDir,"Reference%d_%s.txt" % (i,"f32")))
  333. def paramP(self,i,name=None):
  334. """ Path to a parameters from the ID
  335. Args:
  336. i (int): ID to the params
  337. Raises:
  338. Nothing
  339. Returns:
  340. str : path to the file where to generate the pattern data
  341. """
  342. if name:
  343. return(os.path.join(self._paramDir,"%s%d.txt" % (name,i)))
  344. else:
  345. return(os.path.join(self._paramDir,"Params%d.txt" % i))
  346. def _writeVectorF64(self,i,data):
  347. """ Write pattern data
  348. The format is recognized by the text framework script.
  349. First line is the sample width (B,H or W,D for 8,16,32 or 64 bits)
  350. Second line is number of samples
  351. Other lines are hexadecimal representation of the samples in format
  352. which can be read on big endian ARM.
  353. Args:
  354. j (int): ID of pattern file
  355. data (array): Vector containing the data
  356. Raises:
  357. Nothing
  358. Returns:
  359. Nothing
  360. """
  361. with open(i,"w") as f:
  362. # Write sample dimension nb sample header
  363. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  364. f.write("D\n%d\n" % len(data))
  365. for v in data:
  366. f.write("// %f\n" % v)
  367. f.write("%s\n" % float64_to_hex(v))
  368. def _writeVectorF32(self,i,data):
  369. """ Write pattern data
  370. The format is recognized by the text framework script.
  371. First line is the sample width (B,H or W for 8,16 or 32 bits)
  372. Second line is number of samples
  373. Other lines are hexadecimal representation of the samples in format
  374. which can be read on big endian ARM.
  375. Args:
  376. j (int): ID of pattern file
  377. data (array): Vector containing the data
  378. Raises:
  379. Nothing
  380. Returns:
  381. Nothing
  382. """
  383. with open(i,"w") as f:
  384. # Write sample dimension nb sample header
  385. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  386. f.write("W\n%d\n" % len(data))
  387. for v in data:
  388. f.write("// %f\n" % v)
  389. f.write("%s\n" % float_to_hex(v))
  390. def _writeVectorQ63(self,i,data):
  391. """ Write pattern data
  392. The format is recognized by the text framework script.
  393. First line is the sample width (B,H or W for 8,16 or 32 bits)
  394. Second line is number of samples
  395. Other lines are hexadecimal representation of the samples in format
  396. which can be read on big endian ARM.
  397. Args:
  398. j (int): ID of pattern file
  399. data (array): Vector containing the data
  400. Raises:
  401. Nothing
  402. Returns:
  403. Nothing
  404. """
  405. with open(i,"w") as f:
  406. # Write sample dimension nb sample header
  407. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  408. f.write("D\n%d\n" % len(data))
  409. for v in data:
  410. f.write("// %f\n" % v)
  411. f.write("%s\n" % to_q63(v))
  412. def _writeVectorQ31(self,i,data):
  413. """ Write pattern data
  414. The format is recognized by the text framework script.
  415. First line is the sample width (B,H or W for 8,16 or 32 bits)
  416. Second line is number of samples
  417. Other lines are hexadecimal representation of the samples in format
  418. which can be read on big endian ARM.
  419. Args:
  420. j (int): ID of pattern file
  421. data (array): Vector containing the data
  422. Raises:
  423. Nothing
  424. Returns:
  425. Nothing
  426. """
  427. with open(i,"w") as f:
  428. # Write sample dimension nb sample header
  429. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  430. f.write("W\n%d\n" % len(data))
  431. for v in data:
  432. f.write("// %f\n" % v)
  433. f.write("%s\n" % to_q31(v))
  434. def _writeVectorQ15(self,i,data):
  435. """ Write pattern data
  436. The format is recognized by the text framework script.
  437. First line is the sample width (B,H or W for 8,16 or 32 bits)
  438. Second line is number of samples
  439. Other lines are hexadecimal representation of the samples in format
  440. which can be read on big endian ARM.
  441. Args:
  442. j (int): ID of pattern file
  443. data (array): Vector containing the data
  444. Raises:
  445. Nothing
  446. Returns:
  447. Nothing
  448. """
  449. with open(i,"w") as f:
  450. # Write sample dimension nb sample header
  451. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  452. f.write("H\n%d\n" % len(data))
  453. for v in data:
  454. f.write("// %f\n" % v)
  455. f.write("%s\n" % to_q15(v))
  456. def _writeVectorS16(self,i,data):
  457. """ Write pattern data
  458. The format is recognized by the text framework script.
  459. First line is the sample width (B,H or W for 8,16 or 32 bits)
  460. Second line is number of samples
  461. Other lines are hexadecimal representation of the samples in format
  462. which can be read on big endian ARM.
  463. Args:
  464. j (int): ID of pattern file
  465. data (array): Vector containing the data
  466. Raises:
  467. Nothing
  468. Returns:
  469. Nothing
  470. """
  471. with open(i,"w") as f:
  472. # Write sample dimension nb sample header
  473. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  474. f.write("H\n%d\n" % len(data))
  475. for v in data:
  476. f.write("// %d\n" % v)
  477. f.write("%s\n" % s16(v))
  478. def _writeVectorS32(self,i,data):
  479. """ Write pattern data
  480. The format is recognized by the text framework script.
  481. First line is the sample width (B,H or W for 8,16 or 32 bits)
  482. Second line is number of samples
  483. Other lines are hexadecimal representation of the samples in format
  484. which can be read on big endian ARM.
  485. Args:
  486. j (int): ID of pattern file
  487. data (array): Vector containing the data
  488. Raises:
  489. Nothing
  490. Returns:
  491. Nothing
  492. """
  493. with open(i,"w") as f:
  494. # Write sample dimension nb sample header
  495. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  496. f.write("W\n%d\n" % len(data))
  497. for v in data:
  498. f.write("// %d\n" % v)
  499. f.write("%s\n" % s32(v))
  500. def _writeVectorU32(self,i,data):
  501. """ Write pattern data
  502. The format is recognized by the text framework script.
  503. First line is the sample width (B,H or W for 8,16 or 32 bits)
  504. Second line is number of samples
  505. Other lines are hexadecimal representation of the samples in format
  506. which can be read on big endian ARM.
  507. Args:
  508. j (int): ID of pattern file
  509. data (array): Vector containing the data
  510. Raises:
  511. Nothing
  512. Returns:
  513. Nothing
  514. """
  515. with open(i,"w") as f:
  516. # Write sample dimension nb sample header
  517. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  518. f.write("W\n%d\n" % len(data))
  519. for v in data:
  520. f.write("// %s\n" % v)
  521. f.write("%s\n" % u32(v))
  522. def _writeVectorQ7(self,i,data):
  523. """ Write pattern data
  524. The format is recognized by the text framework script.
  525. First line is the sample width (B,H or W for 8,16 or 32 bits)
  526. Second line is number of samples
  527. Other lines are hexadecimal representation of the samples in format
  528. which can be read on big endian ARM.
  529. Args:
  530. j (int): ID of pattern file
  531. data (array): Vector containing the data
  532. Raises:
  533. Nothing
  534. Returns:
  535. Nothing
  536. """
  537. with open(i,"w") as f:
  538. # Write sample dimension nb sample header
  539. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  540. f.write("B\n%d\n" % len(data))
  541. for v in data:
  542. f.write("// %f\n" % v)
  543. f.write("%s\n" % to_q7(v))
  544. def _writeVectorS8(self,i,data):
  545. """ Write pattern data
  546. The format is recognized by the text framework script.
  547. First line is the sample width (B,H or W for 8,16 or 32 bits)
  548. Second line is number of samples
  549. Other lines are hexadecimal representation of the samples in format
  550. which can be read on big endian ARM.
  551. Args:
  552. j (int): ID of pattern file
  553. data (array): Vector containing the data
  554. Raises:
  555. Nothing
  556. Returns:
  557. Nothing
  558. """
  559. with open(i,"w") as f:
  560. # Write sample dimension nb sample header
  561. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  562. f.write("B\n%d\n" % len(data))
  563. for v in data:
  564. f.write("// %d\n" % v)
  565. f.write("%s\n" % s8(v))
  566. def writeReference(self,j,data,name=None):
  567. if (self._ext == "f64"):
  568. self._writeVectorF64(self.refP(j,name),data)
  569. if (self._ext == "f32"):
  570. self._writeVectorF32(self.refP(j,name),data)
  571. if (self._ext == "q63"):
  572. self._writeVectorQ63(self.refP(j,name),data)
  573. if (self._ext == "q31"):
  574. self._writeVectorQ31(self.refP(j,name),data)
  575. if (self._ext == "q15"):
  576. self._writeVectorQ15(self.refP(j,name),data)
  577. if (self._ext == "q7"):
  578. self._writeVectorQ7(self.refP(j,name),data)
  579. if (self._ext == "u32"):
  580. self._writeVectorU32(self.refP(j,name),data)
  581. if (self._ext == "s8"):
  582. self._writeVectorS8(self.refP(j,name),data)
  583. def writeReferenceQ63(self,j,data,name=None):
  584. self._writeVectorQ63(self.refQ63P(j,name),data)
  585. def writeReferenceQ31(self,j,data,name=None):
  586. self._writeVectorQ31(self.refQ31P(j,name),data)
  587. def writeReferenceS8(self,j,data,name=None):
  588. self._writeVectorS8(self.refS8P(j,name),data)
  589. def writeReferenceS16(self,j,data,name=None):
  590. self._writeVectorS16(self.refS16P(j,name),data)
  591. def writeReferenceS32(self,j,data,name=None):
  592. self._writeVectorS32(self.refS32P(j,name),data)
  593. def writeReferenceF32(self,j,data,name=None):
  594. self._writeVectorF32(self.refF32P(j,name),data)
  595. def writeInput(self,j,data,name=None):
  596. if (self._ext == "f64"):
  597. self._writeVectorF64(self.inputP(j,name),data)
  598. if (self._ext == "f32"):
  599. self._writeVectorF32(self.inputP(j,name),data)
  600. if (self._ext == "q31"):
  601. self._writeVectorQ31(self.inputP(j,name),data)
  602. if (self._ext == "q15"):
  603. self._writeVectorQ15(self.inputP(j,name),data)
  604. if (self._ext == "q7"):
  605. self._writeVectorQ7(self.inputP(j,name),data)
  606. if (self._ext == "u32"):
  607. self._writeVectorU32(self.inputP(j,name),data)
  608. if (self._ext == "s8"):
  609. self._writeVectorS8(self.inputP(j,name),data)
  610. def writeInputF32(self,j,data,name=None):
  611. self._writeVectorF32(self.inputF32P(j,name),data)
  612. def writeInputQ31(self,j,data,name=None):
  613. self._writeVectorQ31(self.inputQ31P(j,name),data)
  614. def writeInputQ15(self,j,data,name=None):
  615. self._writeVectorQ15(self.inputQ15P(j,name),data)
  616. def writeInputQ7(self,j,data,name=None):
  617. self._writeVectorQ7(self.inputQ7P(j,name),data)
  618. def writeInputS32(self,j,data,name=None):
  619. self._writeVectorS32(self.inputS32P(j,name),data)
  620. def writeInputS16(self,j,data,name=None):
  621. self._writeVectorS16(self.inputS16P(j,name),data)
  622. def writeInputS8(self,j,data,name=None):
  623. self._writeVectorS8(self.inputS8P(j,name),data)
  624. def writeInputU32(self,j,data,name=None):
  625. self._writeVectorU32(self.inputU32P(j,name),data)
  626. def writeParam(self,j,data,name=None):
  627. """ Write pattern data
  628. The format is recognized by the text framework script.
  629. First line is the sample width (B,H or W for 8,16 or 32 bits)
  630. Second line is number of samples
  631. Other lines are hexadecimal representation of the samples in format
  632. which can be read on big endian ARM.
  633. Args:
  634. j (int): ID of parameter file
  635. data (array): Vector containing the data
  636. Raises:
  637. Nothing
  638. Returns:
  639. Nothing
  640. """
  641. i=self.paramP(j,name)
  642. with open(i,"w") as f:
  643. # Write sample dimension nb sample header
  644. #np.savetxt(i, data, newline="\n", header="W\n%d" % len(data),comments ="" )
  645. f.write("%d\n" % len(data))
  646. for v in data:
  647. f.write("%d\n" % v)