This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-995] Constant Initializer for ND Array #12677
Closed
Closed
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -869,7 +869,7 @@ def _sync_copyfrom(self, source_array): | |
source_array = np.ascontiguousarray(source_array, dtype=self.dtype) | ||
if source_array.shape != self.shape: | ||
raise ValueError('Shape inconsistent: expected %s vs got %s'%( | ||
str(self.shape), str(source_array.shape))) | ||
str(source_array.shape), str(self.shape))) | ||
check_call(_LIB.MXNDArraySyncCopyFromCPU( | ||
self.handle, | ||
source_array.ctypes.data_as(ctypes.c_void_p), | ||
|
@@ -2479,6 +2479,8 @@ def array(source_array, ctx=None, dtype=None): | |
if isinstance(source_array, NDArray): | ||
dtype = source_array.dtype if dtype is None else dtype | ||
else: | ||
if isinstance(source_array, (float, int)): | ||
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. mx.base.numeric_types is better 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. my concern here is that you implicitly converted 0-d array(constant) to 1-d array here, which may not be very appropriate 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. Ah, my logic was since MXNet NDArray needs a 1d array minimum, I should convert constant. Else, is there a way I can do constant initialization support? Would be great to get some help in that direction. |
||
source_array = [float(source_array)] | ||
dtype = mx_real_t if dtype is None else dtype | ||
if not isinstance(source_array, np.ndarray): | ||
try: | ||
|
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
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.
why switch the order of expected vs got?
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.
Have a look at #12676
I found it to be odd. Hence created an issue and fixed it in this PR
Don't you think so?
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.
@zhreshold could you confirm if the above issue (#12676 ) is right or not? coz the value error it gave sounded confusing due to mismatched shapes. Thanks