|
lambda a, b: np.tensordot(a, b, axes=0), |
Current code:
lambda a, b: np.tensordot(a, b, axes=0)
Proposed replacement:
lambda a, b: np.outer(a, b)
np.tensordot(a, b, axes=0) is a general-purpose tensor operation that, in this case, computes exactly the same result as np.outer(a, b) for 1-D inputs. However, tensordot carries additional overhead from its general implementation, while outer is optimized specifically for outer products. Benchmarks show that np.outer is consistently faster and also more expressive, since it directly conveys the mathematical intent of an outer product.
smol/smol/cofe/space/orbit.py
Line 237 in 8c1e2a7
Current code:
lambda a, b: np.tensordot(a, b, axes=0)Proposed replacement:
lambda a, b: np.outer(a, b)np.tensordot(a, b, axes=0) is a general-purpose tensor operation that, in this case, computes exactly the same result as np.outer(a, b) for 1-D inputs. However, tensordot carries additional overhead from its general implementation, while outer is optimized specifically for outer products. Benchmarks show that np.outer is consistently faster and also more expressive, since it directly conveys the mathematical intent of an outer product.