Why do I get different result when I run scalene on the same python code on MacOS versus Linux? #392
Unanswered
kizombaciao
asked this question in
Q&A
Replies: 1 comment
-
The pasting made kind of a mess of the input indentation. Can you please attach the file? Also, please run the latest version and see if it addresses your issues (which could use a bit more detail - what exactly is the discrepancy you are seeing? For example, Numpy on the latest M1 needs some handholding to build so it uses the Apple GPU...) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I ran the below code using scalene on both MacOS and Linux. However, the results I got on Linux were less comprehensive. I am not sure why there is a disparity and why it seems the results on Linux appears to to be missing a lot of details, when referring to the MacOS results.
Thanks,
import numpy as np
from numpy import linalg as LA
def is_pos_def(x):
"""check if a matrix is symmetric positive definite"""
return np.all(np.linalg.eigvals(x) > 0)
def conjugate_gradient(A, b):
if (is_pos_def(A) == False) | (A != A.T).any():
raise ValueError("Matrix A needs to be symmetric positive definite (SPD)")
r = b
k = 0
x = np.zeros(A.shape[-1])
while LA.norm(r) > 1e-10:
if k == 0:
p = r
else:
gamma = -(p @ A @ r) / (p @ A @ p)
p = r + gamma * p
alpha = (p @ r) / (p @ A @ p)
x = x + alpha * p
r = r - alpha * (A @ p)
k = +1
return x
A = np.random.rand(1000, 1000)
A = A.T @ A # make a symmetric positive definite metrix A
b = np.random.rand(1000)
print(conjugate_gradient(A, b))
Beta Was this translation helpful? Give feedback.
All reactions