[Numpy-discussion] Re: array.T.max() vs array.max(axis=0) performance difference

2025-03-21 Thread Tiziano Zito via NumPy-Discussion

Hi George,

what you see is due to the memory layout of numpy arrays. If you switch your 
array to F-order you'll see that the two functions have the same timings, i.e. 
both are fast (on my machine 25 times faster for the 1_000_000 points case).

Try:

vertices = np.array(np.random.random((n, 2)), order='F')

When your array doesn't fit in L1-cache anymore, either order 'C' or order 'F' 
becomes (much) more efficient depending on which dimension you are internally 
looping through.

You can read more about it here:
https://numpy.org/doc/stable/dev/internals.html#internal-organization-of-numpy-arrays
and
https://numpy.org/doc/stable/reference/arrays.ndarray.html#internal-memory-layout-of-an-ndarray

Hope that helps,
Tiziano


On Fri 21 Mar, 12:10 +0200, George Tsiamasiotis via NumPy-Discussion 
 wrote:

Hello NumPy community!

I was writing a function that calculates the bounding box of a polygon (the 
smallest rectangle that fully contains the polygon, and who's sides are 
parallel to the x and y axes). The input is a (N,2) array containing the 
vertices of the polygon, and the output is a 4-tuple containing the vertices of 
the 2 corners of the bounding box.

I found two ways to do that using the np.min() and np.max() methods, and I was 
surprised to see a significant speed difference, even though they seemingly do 
the same thing.

While for small N the speed is essentially the same, the difference becomes 
noticeable for larger N. >From my testing, the difference seems to plateau, 
with the one way being around 4-5 times faster than the other.

Is there an explanation for this?

Here is a small benchmark I wrote (must be executed with IPython):

import numpy as np
from IPython import get_ipython

vertices = np.random.random((1000, 2))

def calculate_bbox_normal(vertices: np.ndarray) -> tuple[np.float64]:
    xmin, ymin = vertices.min(axis=0)
    xmax, ymax = vertices.max(axis=0)
    return xmin, ymin, xmax, ymax

def calculate_bbox_transpose(vertices: np.ndarray) -> tuple[np.float64]:
    xmin = vertices.T[0].min()
    xmax = vertices.T[0].max()
    ymin = vertices.T[1].min()
    ymax = vertices.T[1].max()
    return xmin, ymin, xmax, ymax

bbox_normal = calculate_bbox_normal(vertices)
bbox_transpose = calculate_bbox_transpose(vertices)

print(f"Equality: {bbox_normal == bbox_transpose}")

for n in [10, 100, 1000, 10_000, 100_000, 1_000_000]:
    print(f"Number of points: {n}")
    vertices = np.random.random((n, 2))
    print("Normal:    ", end="")
    get_ipython().run_line_magic("timeit", "calculate_bbox_normal(vertices)")
    print("Transpose: ", end="")
    get_ipython().run_line_magic("timeit", "calculate_bbox_transpose(vertices)")
    print()




___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: opossumn...@gmail.com


___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] 17ᵗʰ Advanced Scientific Programming in Python in Plovdiv, Bulgaria, 21–28 September, 2025

2025-03-24 Thread Tiziano Zito via NumPy-Discussion
ASPP2025: 17ᵗʰ Advanced Scientific Programming in Python Summer School 
==

https://aspp.school

Scientists spend more and more time writing, maintaining, and debugging 
software. While techniques for doing this efficiently have evolved, only few 
scientists have been trained to use them. As a result, instead of doing their 
research, they spend far too much time writing deficient code and reinventing 
the wheel. In this course we will present a selection of advanced programming 
techniques and best practices which are standard in the industry, but 
especially tailored to the needs of a programming scientist. Lectures are 
interactive and allow students to acquire direct hands-on experience with the 
topics. Students will work in pairs throughout the school and will team up to 
practice the newly learned skills in a real programming project — an 
entertaining computer game.

We use the Python programming language for the entire course. Python works as a 
simple programming language for beginners, but more importantly, it also works 
great in scientific simulations and data analysis. Python is the standard tool 
for the programming scientist due to clean language design, ease of 
extensibility, and the great wealth of open source libraries for scientific 
computing and data visualization.

This school is targeted at PhD students, postdocs and more senior researchers 
from all areas of science. Competence in Python or in another language such as 
Java, JavaScript, C/C++, MATLAB, or R is absolutely required. Basic knowledge 
of Python and git or another version control system is assumed. Participants 
without any prior experience with Python or git should work through the 
proposed introductory material before the course.

We care for diversity and inclusion, and strive for a welcoming atmosphere to 
programming scientists of all levels. In particular, we have focused on 
recruiting an international and gender-balanced pool of students.

Date & Location
===
21–28 September, 2025. Plovdiv, Bulgaria.

Application
===
You can apply online: https://aspp.school

Application deadline: 23:59 UTC, Sunday 1 June, 2025. There will be no deadline 
extension, so be sure to apply on time.
Invitations and notifications of rejection will be sent by Sunday 15 June, 2025.

Participation is for free, i.e. no fee is charged! Participants however should 
take care of travel, living, and accommodation expenses by themselves. 

Program
===
• Large-scale collaborative scientific code development with git and code forges
• Testing and debugging scientific code
• Organizing, documenting, and distributing scientific code
• Data in scientific programming
• Scientific programming patterns in Python
• What every scientist should know about computer architecture
• Writing parallel applications in Python
• Programming in teams

Faculty
===
• Aitor Morales-Gregorio, Faculty of Mathematics and Physics, Charles 
University, Prague, Czechia
• Guillermo Aguilar, Department of Computational Psychology, Technische 
Universität Berlin, Germany
• Jenni Rinker, Department of Wind and Energy Systems, Technical University of 
Denmark, Lyngby, Denmark
• Lisa Schwetlick, Laboratory of Psychophysics, EPFL, Lausanne, Switzerland
• Pamela Hathway, YPOG, Berlin/Nürnberg, Germany
• Pietro Berkes, NAGRA Kudelski, Lausanne, Switzerland
• Rike-Benjamin Schuppner, Institute for Theoretical Biology, 
Humboldt-Universität zu Berlin, Germany
• Tiziano Zito, innoCampus, Technische Universität Berlin, Germany
• Victoria Shevchenko, Inria Saclay Palaiseau and Université Paris Cité, France
• Zbigniew Jędrzejewski-Szmek, Red Hat Inc., Warsaw, Poland

Organizers
==
Head of the organization for ASPP and responsible for the scientific program:
• Tiziano Zito, innoCampus, Technische Universität Berlin, Germany

Organization team in Plovdiv:
• Maya Ivanova Nikolova, MNKnowledge, Sofia, Bulgaria
• Verjinia Metodieva, Charité – Universitätsmedizin Berlin, ECN, Germany

Sponsors

ASPP2025 is hosted by the Technical University of Sofia, Plovdiv branch. The 
organization is done in collaboration with MNKnowledge and with the financial 
and institutional support of the Tübingen AI Center. 

Website: https://aspp.school
Contact: info@aspp.school
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com