Introduction and question about unit conversion of multiples of units

25 views
Skip to first unread message

Sam Lubelsky

unread,
Mar 29, 2024, 5:04:03 AM3/29/24
to sympy
Since I haven't posted to the mailing list before I'll do a quick introduction:

My name is Sam.  I'm from New York City, though I currently live in St. Louis.  I've been programming in python, both in-school and on some side projects, for a few years.  I have worked on a few machine learning projects(cause that's what I'm most interested in!), but I am somewhat out of my depth with a codebase as large as Sympy. 

Now, for some context about my question:
Currently unit conversion works using convert_to(expression_you want to convert, new units) 

For example
from sympy.physics.units import speed_of_light, meter, second convert_to(2*speed_of_light), meter/second)

speed_of_light.convert_to(meter/second) also currently works, but when you write it in this form you can't convert multiples of a unit to another unit

e.g. (3 * speed_of_light).convert_to(meter/second)

or it will break, because a multiple of speed_of_light will be converted to a Mul object, and mul objects don't have a convert_to function.

It would be nice if there was a way to make convert_to work on multiples of units(in the unit.convert_to(other_unit) form) without having to change the core code(Mul.py).  

Does anyone have ideas on if/how this might be possible?



Reply all
Reply to author
Forward
0 new messages