SyntaxError: invalid micropython decorator
SyntaxError: invalid micropython decorator
When trying @micropython.native or @micropython.viper decorator on MicroPython v1.8.4-54-gec078af-dirty on 2016-09-22; WiPy with CC3200.
Do I have to enable it manually somewhere before building MP?
Do I have to enable it manually somewhere before building MP?
Re: SyntaxError: invalid micropython decorator
@micropython.native and @micropython.viper both require MICROPY_EMIT_NATIVE.
https://github.com/micropython/micropyt ... #L757-L762
It looks like EMIT_NATIVE is defined here:
https://github.com/micropython/micropyt ... fig.h#L291
and the wipy (cc3200) has those disabled:
https://github.com/micropython/micropyt ... .h#L41-L42
https://github.com/micropython/micropyt ... #L757-L762
It looks like EMIT_NATIVE is defined here:
https://github.com/micropython/micropyt ... fig.h#L291
and the wipy (cc3200) has those disabled:
https://github.com/micropython/micropyt ... .h#L41-L42
Re: SyntaxError: invalid micropython decorator
Thanks Dave, I will rebuild tomorrow and check if it works.
Could you please suggest some typical test function on which I should observe improvement when defined with @micropython.native or @micropython.viper decorators?
Could you please suggest some typical test function on which I should observe improvement when defined with @micropython.native or @micropython.viper decorators?
Re: SyntaxError: invalid micropython decorator
I've not really used either, but there is some discussion about it here:
http://docs.micropython.org/en/latest/p ... de-emitter
with at least a viper example.
http://docs.micropython.org/en/latest/p ... de-emitter
with at least a viper example.
Re: SyntaxError: invalid micropython decorator
I was not able to build MP with MICROPY_EMIT_THUMB and MICROPY_EMIT_INLINE_THUMB set to (1)
@danicampora - is there a way how to make it work?
Code: Select all
CC ../py/compile.c
../py/compile.c: In function 'compile_built_in_decorator':
../py/compile.c:759:24: error: 'MP_QSTR_native' undeclared (first use in this function)
} else if (attr == MP_QSTR_native) {
^
../py/compile.c:759:24: note: each undeclared identifier is reported only once for each function it appears in
../py/compile.c:761:24: error: 'MP_QSTR_viper' undeclared (first use in this function)
} else if (attr == MP_QSTR_viper) {
^
../py/compile.c:765:24: error: 'MP_QSTR_asm_thumb' undeclared (first use in this function)
} else if (attr == MP_QSTR_asm_thumb) {
^
../py/compile.c: In function 'compile_scope_inline_asm':
../py/compile.c:3147:22: error: 'MP_QSTR_uint' undeclared (first use in this function)
case MP_QSTR_uint: type_sig = MP_NATIVE_TYPE_UINT; break;
^
../py/compile.c:3196:19: error: 'MP_QSTR_label' undeclared (first use in this function)
if (op == MP_QSTR_label) {
^
../py/compile.c:3208:26: error: 'MP_QSTR_align' undeclared (first use in this function)
} else if (op == MP_QSTR_align) {
^
../py/compile.c:3216:26: error: 'MP_QSTR_data' undeclared (first use in this function)
} else if (op == MP_QSTR_data) {
^
make: *** [build/WIPY/release/py/compile.o] Error 1
Re: SyntaxError: invalid micropython decorator
You may need to do a clean after enabling those options.
The auto qstr generator seems to not always regenerate qstrs at the right time. Anytime I see any errors related to qstrs, I typically do a clean and then the problem goes away.
The auto qstr generator seems to not always regenerate qstrs at the right time. Anytime I see any errors related to qstrs, I typically do a clean and then the problem goes away.
Re: SyntaxError: invalid micropython decorator
Dave, it helped, thanks a lot!
Decorator @micropython.native increased performance of my function by almost 10%. I am looking for further improvements.
This is my code - its purpose is to render words consisting of letters - each represented by 20-30 X-Y coordinates defined as two-dimensional lists in a dictionary called "alphabet". I also tried array.array instead but it was not faster.
I am manipulating with CS/NSS pin manualy. If this operation would not be required performance could be increased by approx. 10%. However that would require to implement CS toggling on C module level as it was discussed several months ago in another thread.
Is there any faster way how to perform int to (2)byte conversion in reversed order?
Could SPI.write() and Pin.value() be performed with @micropython.viper decorator?
EDIT: I just discovered that following two calculations are consuming 50% of the runtime:
Maybe I could put them in separate function with @micropython.viper decorator?
Decorator @micropython.native increased performance of my function by almost 10%. I am looking for further improvements.
This is my code - its purpose is to render words consisting of letters - each represented by 20-30 X-Y coordinates defined as two-dimensional lists in a dictionary called "alphabet". I also tried array.array instead but it was not faster.
Code: Select all
@micropython.native
def renderTest(self, text, factor, times):
count = 0
data_array = bytearray(2)
start = time.time()
for x in range(times):
for letterIndex in range(len(text)):
for pointIndex in range(len(alphabet[text[letterIndex]])):
data=self.currentX+factor*alphabet[text[letterIndex]][pointIndex][1] + 12288
data_array[1],data_array[0] = data.to_bytes(2)
self.spiNSS.value(0)
self.spiWrite(data_array)
self.spiNSS.value(1)
data=self.currentY+factor*alphabet[text[letterIndex]][pointIndex][0] + 45056
data_array[1],data_array[0] = data.to_bytes(2)
self.spiNSS.value(0)
self.spiWrite(data_array)
self.spiNSS.value(1)
count+=1
self.currentY+=factor*18
self.currentY = 0
print(time.time()-start)
print(count)
I am manipulating with CS/NSS pin manualy. If this operation would not be required performance could be increased by approx. 10%. However that would require to implement CS toggling on C module level as it was discussed several months ago in another thread.
Is there any faster way how to perform int to (2)byte conversion in reversed order?
Could SPI.write() and Pin.value() be performed with @micropython.viper decorator?
EDIT: I just discovered that following two calculations are consuming 50% of the runtime:
Code: Select all
data=self.currentX+factor*alphabet[text[letterIndex]][pointIndex][1] + 12288
data=self.currentY+factor*alphabet[text[letterIndex]][pointIndex][0] + 45056
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: SyntaxError: invalid micropython decorator
Looking at the innermost loop you're doing repeated lookups which could be cached, something along these lines
I suspect the first two lines can be reduced to one but I can't get my head round it at 7:20am...
Code: Select all
for pointIndex, atli in enumerate(alphabet[text[letterIndex]]):
atli_pi = atli[pointIndex]
data=self.currentX + factor * atl_pi[1] + 12288
data_array[1], data_array[0] = data.to_bytes(2)
self.spiNSS.value(0)
self.spiWrite(data_array)
self.spiNSS.value(1)
data=self.currentY + factor * atli_pi[0] + 45056
data_array[1],data_array[0] = data.to_bytes(2)
self.spiNSS.value(0)
self.spiWrite(data_array)
self.spiNSS.value(1)
count+=1
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: SyntaxError: invalid micropython decorator
@pythoncoder, I wanted to implement your solution, however enumerate() probably does not work with list of lists as expected:
Code: Select all
>>> alphabet["A"]
[[0, 0], [1, 4], [2, 8], [3, 12], [4, 16], [5, 20], [6, 24], [7, 28], [8, 32], [9, 28], [10, 24], [11, 20], [12, 16], [13, 12], [10, 12], [6, 12], [13, 12], [14, 8], [15, 4], [16, 0]]
>>> for pointIndex, atli in enumerate(alphabet["A"]):
... print(atli[pointIndex])
...
...
...
0
4
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
IndexError: index out of range
Re: SyntaxError: invalid micropython decorator
"atli" are the individual elements there, and since they only have 2 items each, it's natural you get IndexError.