-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Change function kron to output a 1d vector when input is 1d #3133
base: develop
Are you sure you want to change the base?
Conversation
Oh, sorry, I misunderstood the discussion in #1753. It should be the case that |
Since we don't deal with matrices above size 2 here, I believe edge case handling, especially for 2D-empty matrices, would be appropriate. Though it may sound naive, suggestions are welcomed. |
I will be frank, the fact that your current change is failing this empty 2D matrix test suggests to me that you're checking for 1D inputs in the wrong place (but I am not sure of that, I haven't tried to debug the code/find the right place). It also suggests to me that there need to be additional tests. For example, the kronecker product of two 1-by-1 matrices should be a 1-by-1 matrix, e.g. |
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.
@Kiki-1234-web . Thanks for your PR. I had a look, and indeed like Glen explained, the new behavior doesn't yet match what we're looking for. In brief:
- 1d inputs -> 1d output
- 2d inputs -> 2d output
- a mix of 1d and 2d inputs -> 2d output
Does that make sense?
@@ -29,13 +29,12 @@ describe('kron', function () { | |||
}) | |||
|
|||
it('should calculate product for empty 2D Arrays', function () { | |||
assert.deepStrictEqual(math.kron([[]], [[]]), [[]]) | |||
assert.deepStrictEqual(math.kron([[]], [[]]), []) |
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.
Since the inputs are 2d arrays, the output should stay a 2d array [[]]
like it was before.
it('should calculate product for 1D Arrays', function () { | ||
assert.deepStrictEqual(math.kron([1, 1], [[1, 0], [0, 1]]), [[1, 0, 1, 0], [0, 1, 0, 1]]) | ||
assert.deepStrictEqual(math.kron([[1, 0], [0, 1]], [1, 1]), [[1, 1, 0, 0], [0, 0, 1, 1]]) | ||
assert.deepStrictEqual(math.kron([1, 2, 6, 8], [12, 1, 2, 3]), [[12, 1, 2, 3, 24, 2, 4, 6, 72, 6, 12, 18, 96, 8, 16, 24]]) | ||
assert.deepStrictEqual(math.kron([1, 2, 6, 8], [12, 1, 2, 3]), [12, 1, 2, 3, 24, 2, 4, 6, 72, 6, 12, 18, 96, 8, 16, 24]) |
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.
This is indeed the change we want 👌. Now, the name of the test is a bit misleading. Can you split the tests? One testing 2d inputs, one testing a mix of 1d and 2d input, and one testing 1d inputs?
@Kiki-1234-web can you have a look at the feedback? |
Sure, I looked at it although got little busy with personal commitments.
Will get back to it in a few days.
…On Wed, 14 Feb 2024 at 1:30 PM, Jos de Jong ***@***.***> wrote:
@Kiki-1234-web <https://github.com/Kiki-1234-web> can you have a look at
the feedback?
—
Reply to this email directly, view it on GitHub
<#3133 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVMIDYJUP53IAMJFBDJ32R3YTRVINAVCNFSM6AAAAABCEEEDUWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBTGI2DONZSG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thanks! |
When both inputs are 1D vectors, kron function return 1D vector as an output.