Tools.py 24 KB

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