New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative fix for Dynamic(Object)Array::clone() #3721
Merged
karlnapf
merged 3 commits into
shogun-toolbox:develop
from
lkuchenb:fixDynObjArrayClone2
Mar 23, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ template <class T> class CDynamicArray :public CSGObject | |
public: | ||
/** default constructor */ | ||
CDynamicArray() | ||
: CSGObject(), m_array(), name("Array") | ||
: CSGObject(), m_array() | ||
{ | ||
dim1_size=1; | ||
dim2_size=1; | ||
|
@@ -48,7 +48,7 @@ template <class T> class CDynamicArray :public CSGObject | |
* @param p_dim3_size dimension 3 | ||
*/ | ||
CDynamicArray(int32_t p_dim1_size, int32_t p_dim2_size=1, int32_t p_dim3_size=1) | ||
: CSGObject(), m_array(p_dim1_size*p_dim2_size*p_dim3_size), name("Array") | ||
: CSGObject(), m_array(p_dim1_size*p_dim2_size*p_dim3_size) | ||
{ | ||
dim1_size=p_dim1_size; | ||
dim2_size=p_dim2_size; | ||
|
@@ -65,7 +65,7 @@ template <class T> class CDynamicArray :public CSGObject | |
* @param p_copy_array if array must be copied | ||
*/ | ||
CDynamicArray(T* p_array, int32_t p_dim1_size, bool p_free_array, bool p_copy_array) | ||
: CSGObject(), m_array(p_array, p_dim1_size, p_free_array, p_copy_array), name("Array") | ||
: CSGObject(), m_array(p_array, p_dim1_size, p_free_array, p_copy_array) | ||
{ | ||
dim1_size=p_dim1_size; | ||
dim2_size=1; | ||
|
@@ -84,7 +84,7 @@ template <class T> class CDynamicArray :public CSGObject | |
*/ | ||
CDynamicArray(T* p_array, int32_t p_dim1_size, int32_t p_dim2_size, | ||
bool p_free_array, bool p_copy_array) | ||
: CSGObject(), m_array(p_array, p_dim1_size*p_dim2_size, p_free_array, p_copy_array), name("Array") | ||
: CSGObject(), m_array(p_array, p_dim1_size*p_dim2_size, p_free_array, p_copy_array) | ||
{ | ||
dim1_size=p_dim1_size; | ||
dim2_size=p_dim2_size; | ||
|
@@ -104,7 +104,7 @@ template <class T> class CDynamicArray :public CSGObject | |
*/ | ||
CDynamicArray(T* p_array, int32_t p_dim1_size, int32_t p_dim2_size, | ||
int32_t p_dim3_size, bool p_free_array, bool p_copy_array) | ||
: CSGObject(), m_array(p_array, p_dim1_size*p_dim2_size*p_dim3_size, p_free_array, p_copy_array), name("Array") | ||
: CSGObject(), m_array(p_array, p_dim1_size*p_dim2_size*p_dim3_size, p_free_array, p_copy_array) | ||
{ | ||
dim1_size=p_dim1_size; | ||
dim2_size=p_dim2_size; | ||
|
@@ -121,7 +121,7 @@ template <class T> class CDynamicArray :public CSGObject | |
* @param p_dim3_size dimension 3 | ||
*/ | ||
CDynamicArray(const T* p_array, int32_t p_dim1_size=1, int32_t p_dim2_size=1, int32_t p_dim3_size=1) | ||
: CSGObject(), m_array(p_array, p_dim1_size*p_dim2_size*p_dim3_size), name("Array") | ||
: CSGObject(), m_array(p_array, p_dim1_size*p_dim2_size*p_dim3_size) | ||
{ | ||
dim1_size=p_dim1_size; | ||
dim2_size=p_dim2_size; | ||
|
@@ -545,21 +545,6 @@ template <class T> class CDynamicArray :public CSGObject | |
/** shuffles the array with external random state */ | ||
inline void shuffle(CRandom * rand) { m_array.shuffle(rand); } | ||
|
||
/** set array's name | ||
* | ||
* @param p_name new name | ||
*/ | ||
inline void set_array_name(const char* p_name) | ||
{ | ||
name=p_name; | ||
} | ||
|
||
/** get array's name | ||
* | ||
* @return array's name | ||
*/ | ||
inline const char* get_array_name() const { return name; } | ||
|
||
/** display this array */ | ||
inline void display_array() | ||
{ | ||
|
@@ -619,6 +604,16 @@ template <class T> class CDynamicArray :public CSGObject | |
m_array.resize_array(m_array.get_num_elements(), true); | ||
} | ||
|
||
virtual CSGObject* clone() | ||
{ | ||
CDynamicArray * cloned = (CDynamicArray*) CSGObject::clone(); | ||
// Since the array vector is registered with | ||
// current_num_elements as size (see parameter | ||
// registration) the cloned version has less memory | ||
// allocated than known to dynarray. We fix this here. | ||
cloned->m_array.num_elements = cloned->m_array.current_num_elements; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So again:
|
||
return cloned; | ||
} | ||
|
||
private: | ||
|
||
|
@@ -630,9 +625,6 @@ template <class T> class CDynamicArray :public CSGObject | |
m_parameters->add_vector(&m_array.array, | ||
&m_array.current_num_elements, "array", | ||
"Memory for dynamic array."); | ||
SG_ADD(&m_array.num_elements, | ||
"num_elements", | ||
"Number of Elements.", MS_NOT_AVAILABLE); | ||
SG_ADD(&m_array.resize_granularity, | ||
"resize_granularity", | ||
"shrink/grow step size.", MS_NOT_AVAILABLE); | ||
|
@@ -644,6 +636,9 @@ template <class T> class CDynamicArray :public CSGObject | |
"free_array", | ||
"whether array must be freed", | ||
MS_NOT_AVAILABLE); | ||
SG_ADD(&dim1_size, "dim1_size", "Dimension 1", MS_NOT_AVAILABLE); | ||
SG_ADD(&dim2_size, "dim2_size", "Dimension 2", MS_NOT_AVAILABLE); | ||
SG_ADD(&dim3_size, "dim3_size", "Dimension 3", MS_NOT_AVAILABLE); | ||
} | ||
|
||
protected: | ||
|
@@ -659,9 +654,6 @@ template <class T> class CDynamicArray :public CSGObject | |
|
||
/** dimension 3 */ | ||
int32_t dim3_size; | ||
|
||
/** array's name */ | ||
const char* name; | ||
}; | ||
} | ||
#endif /* _DYNAMIC_ARRAY_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaaah, so much nicer :)