Questions tagged [deep-copy]
A deep copy of an object is a separate, fully independent duplicate of that object, such that any references / pointers it holds to other objects refer to deep copies of those to which the original's refer. Use this tag for questions regarding implementing or using deep copying methods.
deep-copy
1,497
questions
0
votes
0
answers
41
views
Is this syntax and method for making a deep copy of a List of interfaces in VB.NET, constructing new instances from interfaces, flawed?
I'm learning VB.NET and finding that there are dozens of ways to get the same behavior. So I'd like to know if there's a better way to solve the following case.
Assume a simple interface and a class ...
0
votes
1
answer
27
views
Testing Value Objects in DDD, "Implementing Domain Driven Design"
In the book "Implementing Domain Driven Design" of Vaughn Vernon, in the Testing of Value Objects section, the author talks about how we can use just shallow copy instead of deep copy to ...
3
votes
1
answer
71
views
What is the internal implementation of `copy.deepcopy()` in Python and how to override `__deepcopy__()` correctly?
When reading Antony Hatchkins' answer to "How to override the copy/deepcopy operations for a Python object?", I am confused about why his implementation of __deepcopy()__ does not check memo ...
5
votes
1
answer
91
views
Why `set` objects do not use `__newobj__` function to unpickle like other built-in container types?
I am recently writing a batch of customized container classes which are mostly inherited from built-in list, dict and set types, and I surprisingly encountered an error that the interpreter will raise ...
0
votes
0
answers
37
views
deepcopy fails with object that contains objects that contain sets that point to each other with __hash__
This MWE builds a Network class and a Node class. A Node has attributes called predecessors and successors, each of which is a set that will contain other Nodes. Functions in the two classes manage ...
2
votes
3
answers
122
views
Does the nums array make a deep copy of letters[2:5] = ['C', 'D', 'E']?
I am learning shallow v.s. deep copying a list in Python. I learned that there're two ways to create copies that have the original values unchanged and only modify the new values or vice versa. They'...
0
votes
0
answers
46
views
Deep and shallow copy [duplicate]
I have trouble understanding the deep and shallow copy, and how the method .clone() works in Java. Some sources say it creates a shallow copy, others say it's deep.
public class Kopie {
public ...
0
votes
1
answer
56
views
Implementing clone() in a Generic Class with Cloneable Bound Leads to Unchecked Cast and Access Errors
I'm working on extending a generic Node class to create a GenericNode class for a data structure exercise. The GenericNode class is generic, bounded above by the Cloneable interface, and implements ...
0
votes
0
answers
12
views
List append dictionary - handling missing data
For reading a HTML-tree, I have a script that reads the element-tree. However, the problem I have is that with creating a list, the script uses for a missing value, the last known value.
However, ...
-1
votes
1
answer
84
views
How do you deep copy a variant of pointers in C++?
I have a std::variant whose alternatives are all pointers.
class a {
public:
int* placeholder;
a(a& _copy) { /* Does a deep copy */ }
}
class b {
// For demonstrational purposes, ...
0
votes
1
answer
165
views
How to solve deepcopy error of a pruned model in pytorch
I am trying to build a RL model, where my actor network has some pruned connections.
When using the data collector SyncDataCollector from torchrl, the deepcopy fails (see error below).
This seems to ...
0
votes
1
answer
66
views
Is it absolutely the case that Swift >will not< deep copy a large array, when one "guard let" the array?
typealias Stuff = [[String]] // typically zillions of items
var stuff: [String: Stuff] = [:] // tens of these
When I deep copy† a Stuff,
spare: Stuff = original{
let line = $0.map{ $0 }
...
0
votes
0
answers
65
views
Duration of binary serialization increased after serialize and deserialize an object in json serialization
I've used NewtonSoft.Json to serialize an object and save it into a file. This object contains the whole data of a project created in my software. I read this file (deserialize) and create my project ...
0
votes
1
answer
166
views
Leetcode 133. Clone Graph: DFS deep copy is not getting accepted
I am trying to solve LeetCode problem 133. Clone Graph:
Given a reference of a node in a connected undirected graph.
Return a deep copy (clone) of the graph.
Each node in the graph contains a value (...
0
votes
1
answer
151
views
deep_cloneable gem (cloning of activerecord with associations)
I want to be able to clone objects of class A along with all their (cloned) B, C and D associations.
I have
classes A, B C & D:
A has_many Bs
A has_many Cs
A has_many Ds through Bs
B belongs_to ...