Skip to content

Removed SciPy imports in Manim, making it an indirect dependency #3532

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

Closed
wants to merge 1 commit into from

Conversation

chopan050
Copy link
Contributor

@chopan050 chopan050 commented Dec 16, 2023

Overview: What does this pull request change?

I removed all the SciPy imports in Manim, using NumPy functions instead. Thus, Scipy would become just an indirect dependency of NetworkX, used in Graph (and by extension Polyhedron) for generating the graph layouts which require Scipy.

Motivation and Explanation: Why and how do your changes improve the library?

manim.camera.camera

scipy.spatial.distance.pdist, a function to generate a matrix of pairwise distances between two arrays of points, was imported to calculate... the distance between a single pair of points (and then ndarray.item() was used to extract the only element in the generated 1x1 matrix as a float). In this scenario, pdist is unnecessary and we can just use np.linalg.norm on the distance vector between the two requested points... vector which already existed beforehand (right_vect and down_vect).

manim.utils.bezier

scipy.linalg.solve_banded was used in get_smooth_handle_points for solving a system of equations to find the required handles for a smooth cubic spline. In PR #3281 I already rewrote that function in a way which doesn't use SciPy, so I just copy-pasted that solution.

manim.utils.simple_functions

The choose function called scipy.special.choose to calculate combinatorial coefficients. The only place where choose was used was in manim.utils.bezier, where all the choose(n, k) coefficients were requested for all k in [0, n], or sometimes even for all n in [0, num_points], wasting too many intermediate calculations. Therefore, I replaced it with a custom get_pascal_triangle function which calculates in a single pass a memo for the entire Pascal triangle with the coefficients up to choose(n, n). Then, I made some slight modifications to the manim.utils.bezier functions which used choose.

manim.utils.space_ops

scipy.spatial.transform.Rotation.from_rotvec was used to calculate a rotation matrix. I replaced it with a custom implementation, explaining all the process in the docstring.

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@chopan050 chopan050 changed the title Removed SciPy dependency Removed SciPy imports in Manim, making it an indirect dependency Dec 17, 2023
@Viicos
Copy link
Member

Viicos commented Dec 17, 2023

Nice, always good to reduce the amount of dependencies we have. Will review when I have some time

@chopan050 chopan050 added refactor Refactor or redesign of existing code dependencies Pull requests that update a dependency file labels Dec 21, 2023
@behackl behackl closed this Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file refactor Refactor or redesign of existing code
Projects
Status: Rejected
Development

Successfully merging this pull request may close these issues.

3 participants