Skip to content
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

Cross product primitive implemented #99

Merged
merged 5 commits into from
Nov 7, 2017
Merged

Cross product primitive implemented #99

merged 5 commits into from
Nov 7, 2017

Conversation

parsa
Copy link
Contributor

@parsa parsa commented Nov 2, 2017

Part of issue #2

@hkaiser
Copy link
Member

hkaiser commented Nov 2, 2017

The NumPy docs say (see https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.cross.html):

The cross product of a and b in R^3 is a vector perpendicular to both a and b. If a and b are arrays of vectors, the vectors are defined by the last axis of a and b by default, and these axes can have dimensions 2 or 3. Where the dimension of either a or b is 2, the third component of the input vector is assumed to be zero and the cross product calculated accordingly. In cases where both input vectors have dimension 2, the z-component of the cross product is returned.

IOW, we should add support for a cross product of 2 dimensional arrays as well.

@parsa parsa force-pushed the cross_product branch 6 times, most recently from d1ff86f to 84ae384 Compare November 3, 2017 20:04
@parsa
Copy link
Contributor Author

parsa commented Nov 3, 2017

After experimenting with NumPy a bit I found these differences with my current implementation that I have to address:

  • Vectors must have exactly 2 or 3 elements (current code accepts vectors with fewer than 3 elements)
  • It's possible to perform cross product on a vector and a matrix (Not possible currently)
np.cross([1, 2], [[4, 5], [7, 8], [1, 2]])
array([-3, -6,  0])
  • The matrices can have 2 columns, too
np.cross([1, 2, 3], [[4, 5], [7, 8], [1, 2]])
array([[-15,  12,  -3],
       [-24,  21,  -6],
       [ -6,   3,   0]])

blaze::DynamicMatrix<double> v2{{4.0, 5.0, 6.0}, {1.0, 2.0, 3.0}};

blaze::DynamicMatrix<double> expected{{-3.0, 6.0, -3.0}, {3.0, -6.0, 3.0}};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three tests above don't look complete.

Copy link
Member

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thank you!

@hkaiser hkaiser merged commit 3152f91 into master Nov 7, 2017
@hkaiser hkaiser deleted the cross_product branch November 7, 2017 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants