Closed Durman closed 6 years ago
Im not certain this is wrong, you should also show the textbased output,
it's interesting however, that it's not symmetrical.. if you look at Vector In's source, maybe you can pinpoint why this is. Probably elements are extended to be as long as the first element, unless the current element is longer than the first or previous element.
After first cycle For, Y and Z coordinate are filled and have 5 elements. :/
but is it wrong or unexpected or undesired.
@zeffii
but is it wrong or unexpected or undesired.
Of course it is wrong. Look:
for i in range(max_obj):
max_v = max(map(len, (X_[i], Y_[i], Z_[i])))
print('Y_ -', Y_)
fullList(X_[i], max_v)
fullList(Y_[i], max_v)
fullList(Z_[i], max_v)
series_vec.append(list(zip(X_[i], Y_[i], Z_[i])))
We can see here that fullList(Y_[i], max_v)
didn't fill values for item object but do it for all objects.
@zeffii fullList
function can work with nested lists correctly?
i've had a few beers :) i don't know what to think about this. 🍻
see implementation:
@zeffii I understood what is wrong. When we use fullList first time it create references on the last object, than when we use fullList second time we change one object but all objects are changed. Simple example:
from sverchok.data_structure import fullList
data = [[0]]
fullList(data,2)
fullList(data[0],2)
print(data)
We expected to see [[0,0],[0]], but:
yes, both objects inside data
are the same object.. (by id... and by value)
data = [[0]]
fullList(data,2)
fullList(data[0],2)
print(data)
for obj in data:
print(id(obj)) # <---- this is the same value, both times.
unlike in this example, where both objects will be a different id
item_one = [0, 34]
item_two = [30, 0]
data = [item_one, item_two]
print(id(data[0]))
print(id(data[1]))
something like
# from sverchok.data_structure import fullList
def fullList(l, count):
import copy
"""extends list l so len is at least count if needed with the
last element of l"""
d = count - len(l)
if d > 0:
l.extend([copy.deepcopy(l[-1])] * d)
return
data = [[0]]
fullList(data,2)
for obj in data:
print(id(obj))
fullList(data[0],2)
for obj in data:
print(id(obj))
makes
[[0, 0], [0]]
and we might do something like this:
for upper_register in lists:
max_len = ...
a = fullList_deep_copy(.....) # <--- deep copy is important here..
...
for lower_register in lists:
max_len = ...
a = fullList(.....)
...
we also have a parameter in socket.sv_get(deepcopy=True)
, that would be an alternative option.
But whatever we do, consider that any change would need to be in an MK2, some people might be relying on the old behaviour ( which I think too, is probably incorrect...)
@Durman I welcome you to propose an alternative algorithm that does output the desired data. add a BoolProperty in the class definition, and reference it in draw_buttons_ext
and in process
.
class ...
advanced_mode = BoolProperty(name='advanced deep copy')
...
def draw_buttons_ext(self, context, layout):
layout.row().prop(self, 'advanced_mode')
def process(self):
...
if self.advanced_mode:
... new code
else:
... original code
@zeffii Yes, I'll do it soon.
closing issue. cause established. we can continue talk in the PR https://github.com/nortikin/sverchok/pull/2019
should push soon.