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

Add spade shape #195

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add spade shape #195

wants to merge 3 commits into from

Conversation

kevinr1299
Copy link

@kevinr1299 kevinr1299 commented Jul 13, 2024

Fixes #163

Describe your changes

Add the logic to morph into a spade shape

Checklist

  • Test cases have been modified/added to cover any code changes.
  • Docstrings have been modified/created for any code changes.
  • All linting and formatting checks pass (see the contributing guidelines for more information).

@github-actions github-actions bot added testing Relating to the testing suite shapes Work relating to shapes module labels Jul 13, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first pull request to Data Morph! Please familiarize yourself with the contributing guidelines, if you haven't already.

@stefmolin stefmolin added this to the 0.3.0 milestone Jul 13, 2024
Copy link

codecov bot commented Jul 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.43%. Comparing base (2b0666e) to head (48f72d5).
Report is 31 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #195      +/-   ##
==========================================
+ Coverage   98.38%   98.43%   +0.04%     
==========================================
  Files          43       43              
  Lines        1737     1791      +54     
  Branches      345      359      +14     
==========================================
+ Hits         1709     1763      +54     
  Misses         25       25              
  Partials        3        3              
Files Coverage Δ
src/data_morph/shapes/factory.py 100.00% <ø> (ø)
src/data_morph/shapes/points.py 100.00% <100.00%> (ø)
tests/shapes/test_points.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

@stefmolin stefmolin changed the title Feat/spade Add spade shape Jul 17, 2024
Copy link
Owner

@stefmolin stefmolin left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, @kevinr1299 – I'm very excited for this shape!

Comment on lines +319 to +322
from data_morph.data.loader import DataLoader
from data_morph.shapes.points import Heart

_ = Spade(DataLoader.load_dataset('panda')).plot()
Copy link
Owner

Choose a reason for hiding this comment

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

This code gets executed while building the docs, so this won't work as is.

Suggested change
from data_morph.data.loader import DataLoader
from data_morph.shapes.points import Heart
_ = Spade(DataLoader.load_dataset('panda')).plot()
from data_morph.data.loader import DataLoader
from data_morph.shapes.points import Spade
_ = Spade(DataLoader.load_dataset('panda')).plot()

Comment on lines +334 to +343
# Graph heart curve
x_shift = sum(x_bounds) / 2
y_shift = sum(y_bounds) / 2

t = np.linspace(-3, 3, num=90)

heart_x = -(16 * np.sin(t) ** 3)
heart_y = -(
13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
)
Copy link
Owner

Choose a reason for hiding this comment

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

Since we are using the heart equations, we should share the logic rather than duplicate it.

# Graph left wing
left_t = np.linspace(-6, 0, num=12)
left_x = left_t
left_y = [0.278 * math.pow(point + 6.0, 2) - 16.0 for point in left_t]
Copy link
Owner

Choose a reason for hiding this comment

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

Let's use numpy instead of math and vectorize this. https://numpy.org/doc/stable/reference/generated/numpy.power.html

Comment on lines +346 to +348
line_t = np.linspace(-6, 6, num=12)
line_x = line_t
line_y = [-16 for _ in line_t]
Copy link
Owner

Choose a reason for hiding this comment

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

What about this?

Suggested change
line_t = np.linspace(-6, 6, num=12)
line_x = line_t
line_y = [-16 for _ in line_t]
line_x = np.linspace(-6, 6, num=12)
line_y = np.repeat(-16, 12)

@@ -1,6 +1,7 @@
"""Shapes that are composed of points."""

import itertools
import math
Copy link
Owner

Choose a reason for hiding this comment

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

We should be able to just use numpy here.

Suggested change
import math

Copy link
Owner

@stefmolin stefmolin left a comment

Choose a reason for hiding this comment

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

I left some comments above around speeding up the shape creation and reducing the duplication with the heart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shapes Work relating to shapes module testing Relating to the testing suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add spade target shape
2 participants