Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loops over columns vs loops over rows #20

Open
cantaro86 opened this issue Feb 6, 2024 · 0 comments
Open

Loops over columns vs loops over rows #20

cantaro86 opened this issue Feb 6, 2024 · 0 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@cantaro86
Copy link
Owner

For loops over rows is faster than over columns.

I have already updated the code in commit 8fe948e, where this code:

X = np.zeros((paths, N))
for t in range(0, N - 1):
    X[:, t + 1] = self.theta + np.exp(-self.kappa * dt) * (X[:, t] - self.theta) + std_dt * W[:, t]

was replaced by this:

X = np.zeros((N, paths))
for t in range(0, N - 1):
    X[t + 1, :] = self.theta + np.exp(-self.kappa * dt) * (X[t, :] - self.theta) + std_dt * W[t, :]  

(there was no need to swap rows and cols where the code was vectorized and there are no for loops)

To improve the speed, we should invert rows and columns in each PDE solver. There are many PDEs in this repo, so it is long and hard work. I'm not going to work on this shortly.

In addition to swapping the columns with the rows, we also need to place boundary conditions in different positions inside the matrix.
For instance, for a problem that goes backward in time (such as the BS PDE in notebook 2.1), I used to define the terminal BC in the last column. In the new version, the "terminal BC" should be placed in the last row.

@cantaro86 cantaro86 added enhancement New feature or request wontfix This will not be worked on labels Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant