Tools.py 23 KB

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