Tools.py 23 KB

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