Giter Club home page Giter Club logo

Comments (5)

ghevcoul avatar ghevcoul commented on June 24, 2024 3

NumPy is generally only faster than pure Python for operations on large arrays. I don't remember the exact switching point, but most of the benchmarks I've seen don't show benefits for NumPy arrays over Python lists until you have on the order of a few thousand array elements.

I don't have a good sense of everywhere the cube_vertices() function is used in the code, but if it was refactored to take a list of blocks in a region and return the list of vertices for each block, rather than taking a single block, then a NumPy implementation might be faster.

from pycraft.

TristanTrim avatar TristanTrim commented on June 24, 2024

The change_sector function could also benefit from being matrix addition.
https://github.com/traverseda/pycraft/blob/master/pycraft/world.py#L302

from pycraft.

TristanTrim avatar TristanTrim commented on June 24, 2024

I notice that I'm confused, but re-implementing cube_vertices in numpy made it slower. If anyone knows why this is, I'm pretty curious.

Check it out on this branch if you curious:
https://github.com/TristanTrim/pycraft/blob/numpy_cube_vertices/pycraft/util.py

Original cube_vertices function:
Average time for moving a cube is 3.7735462188720705e-06 over 10000 tests
Numpy re-implementation:
Average time for moving a cube is 1.2723827362060548e-05 over 10000 tests
Numpy re-implementation without (necessary) array.reshape call:
Average time for moving a cube is 8.726072311401368e-06 over 10000 tests

from pycraft.

traverseda avatar traverseda commented on June 24, 2024

It seems to be because the costs of creating an array in numpy are a lot more then the costs of creating an array in plain python.

from pycraft.

TristanTrim avatar TristanTrim commented on June 24, 2024

if it was refactored to take a list of blocks in a region and return the list of vertices for each block

Yeah, this sound's good. I'm attempting it now, with some other refactoring.

from pycraft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.