BlockResearchGroup / compas_tna

Form finding of funicular networks in compression with vertical loads using Thrust Network Analysis
https://blockresearchgroup.github.io/compas_tna
MIT License
13 stars 9 forks source link

cast values as floats before reattributing them to form #24

Closed tkmmark closed 4 years ago

tkmmark commented 4 years ago

please check all equilibration methods involving numpy as an example:

image

this is to ensure that attributes are not np.float64 but float so that the form diagrams can be json-serialisable, and therefore makes it possible for form diagrams to be saved.........................................................................................

tomvanmele commented 4 years ago

this is unnecessary

>>> from numpy import float64
>>> from compas.datastructures import Mesh
>>> import compas
>>> mesh = Mesh.from_obj(compas.get('faces.obj'))
>>> mesh.vertex_attribute(mesh.get_any_vertex(), 'x', float64(1))
>>> mesh.to_json('test.json')
>>> 
tkmmark commented 4 years ago

@brgcode

It is true that the use of numpy floats per se does not create any issue now. But it can easily lead to downstream complications when one is then working with the stored attributes, such as with logical operators, since not all numpy datatypes with python analogues can be serialised...

image

tomvanmele commented 4 years ago

again, unnecessary...

>>> from numpy import bool_
>>> from compas.datastructures import Mesh
>>> import compas
>>> mesh = Mesh.from_obj(compas.get('faces.obj'))
>>> mesh.vertex_attribute(0, 'x', bool_(1))
>>> type(mesh.vertex_attribute(0, 'x'))
<class 'numpy.bool_'>
>>> mesh.to_json('test.json')
>>>
tkmmark commented 4 years ago

@brgcode Ah, you mean Gonzalo added the support to the DataEncoder in the Sep 21 merge. I see now, thanks.