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

[bug] Fix MatrixFreeCG so it can handle multiple input sizes. #8070

Merged

Conversation

houkensjtu
Copy link
Contributor

Brief Summary

Previously, MatrixFreeCG inappropriately assume that the intermediate vectors used in CG solver are all two-dimensional ti.field. This is incorrect because the dimension of Ap p and r should be consistent with input b and x.

Walkthrough

Instead of simply put vector_fields_builder.dense(ti.ij, size).place(p, r, Ap), now it's based on the length of size.

def MatrixFreeCG(A, b, x, tol=1e-6, maxiter=5000, quiet=True):
    ...                                                                                                                                                                          
    vector_fields_builder = ti.FieldsBuilder()                                                                                                                                                                                          
    p = ti.field(dtype=solver_dtype)                                                                                                                                                                                                    
    r = ti.field(dtype=solver_dtype)                                                                                                                                                                                                    
    Ap = ti.field(dtype=solver_dtype)                                                                                                                                                                                                   
    if len(size) == 1:     # Determine the `axes` argument based on the length of `size`                                                                                                                                                                                                             
        axes = ti.i                                                                                                                                                                                                                     
    elif len(size) == 2:                                                                                                                                                                                                                
        axes = ti.ij                                                                                                                                                                                                                    
    elif len(size) == 3:                                                                                                                                                                                                                
        axes = ti.ijk                                                                                                                                                                                                                   
    else:                                                                                                                                                                                                                               
        raise TaichiRuntimeError(f"MatrixFreeCG currently cannot support {len(size)}-D inputs.")                                                                                                                                        
    vector_fields_builder.dense(axes, size).place(p, r, Ap) 

@netlify
Copy link

netlify bot commented May 24, 2023

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit 282a697
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/6476ea50e08abe00081b4937
😎 Deploy Preview https://deploy-preview-8070--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@neozhaoliang neozhaoliang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@neozhaoliang neozhaoliang merged commit 3332eee into taichi-dev:master May 31, 2023
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.

3 participants