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

Interpolation matrix multiply (testing...) #414

Closed
wants to merge 8 commits into from
Closed

Conversation

ecomodeller
Copy link
Member

Vector multiplication in loop replaced with matrix multiplication. (See #413)

Still left to do: create weights matrix without loop.

@ecomodeller ecomodeller changed the title Interpolation matrix multiply Interpolation matrix multiply (testing...) Sep 5, 2022
@jsmariegaard
Copy link
Member

I think it's better just to replace the whole thing with:

def _interp_itemstep(data, elem_ids, weights=None):
    if weights is None:
        return data[elem_ids]
    else:
        return np.sum(data[elem_ids]*weights, axis=1)

This is equivalent to taking the dot product of each row but much much faster.

@jsmariegaard
Copy link
Member

jsmariegaard commented Sep 6, 2022

Closer investigation shows that this is needed:

  def _interp_itemstep(data, elem_ids, weights=None):
    if weights is None:
      return data[elem_ids]
    else:
      idat = data[elem_ids] * weights
      return np.sum(idat, axis=1) if weights.ndim == 2 else idat

To also handle the cases when n_nearest=1...

@ecomodeller ecomodeller closed this Sep 6, 2022
@ecomodeller ecomodeller deleted the interp_matrix branch September 6, 2022 06:33
@jsmariegaard
Copy link
Member

You closed this? But wouldn't it be good to implement my suggestion?

@ecomodeller
Copy link
Member Author

Sure, I'll create a new branch with a fresh start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants