Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:26:43+00:00 2026-06-04T13:26:43+00:00

Hi I’m using f2py to wrap the lapack routine dgesvd, by compiling the dgesvd.f

  • 0

Hi I’m using f2py to wrap the lapack routine dgesvd, by compiling the dgesvd.f file and linking it against llapack, as explained here

according to the docstring, the dgesvd module has the signature:

dgesvd - Function signature:
  dgesvd(jobu,jobvt,m,n,a,s,u,vt,work,lwork,info,[lda,ldu,ldvt])
Required arguments:
  jobu : input string(len=1)
  jobvt : input string(len=1)
  m : input int
  n : input int
  a : input rank-2 array('d') with bounds (lda,*)
  s : input rank-1 array('d') with bounds (*)
  u : input rank-2 array('d') with bounds (ldu,*)
  vt : input rank-2 array('d') with bounds (ldvt,*)
  work : input rank-1 array('d') with bounds (*)
  lwork : input int
  info : input int
Optional arguments:
  lda := shape(a,0) input int
  ldu := shape(u,0) input int
  ldvt := shape(vt,0) input int

Then I use the following ocde to call the module:

mat = rand(20,30)
out_u,out_s,out_vh = zeros((20,20)), zeros((20,)), zeros((30,30))
rows, cols = shape(mat)
workspace = zeros((rows*cols))
out_info = 0

dgesvd(jobu='S', 
    jobvt='S',
    m=rows,
    n=cols,
    a=mat,
    s=out_s,
    u=out_u,
    vt=out_vh,
    work=workspace,
    lwork=rows*cols,
    info=out_info)

Which gives me the correct singular values stored in out_s, but the matrices out_u and out_vh are still only filled with zeros, do I have to do something differently to get the left/right singular vectors as well ?

The code runs through, without any error, which means that out_info is 0.

(The argument ‘S’ for jobu and jobvt tells the routine to compute only the first min(m,n) singular vectors. Changing it to ‘A’, does not make any difference)

Any Ideas are highly appreciated!
Thanks
Mischa

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:26:45+00:00Added an answer on June 4, 2026 at 1:26 pm

    f2py creates python wrappers to Fortran code, but the python functions that are created are not intended to be called exactly like Fortran code. In Fortran, it is common practice to pass the output variables as an argument to the subroutine. This is not “pythonic”; besides, python doesn’t really support subroutines in the same way as Fortran. For this reason, f2py turns your Fortran subroutine into a python function, and thus all output variables are returned by the function, not included in the call signature. So, you would have to call the function this way:

    out_s, out_u, out_vh, info = dgesvd(jobu='S', 
                                        jobvt='S',
                                        m=rows,
                                        n=cols,
                                        a=mat,
                                        work=workspace,
                                        lwork=rows*cols)
    

    However, the LAPACK routine is written in FORTRAN77, so it does not have any INTENT declarations for the input/output variables. f2py uses the INTENT declarations to figure out which variables are used as input, and which are to be returned as output. Based on the function signature that you posted, f2py has assumed that all variables are input, which is not what you want. For this reason, I recommend writing your own Fortran 90 wrapper routine that calls dgesvd, so that you can add INTENT declarations yourself to give f2py some hints. I personally would also use the wrapper to allocate the work array to pass to dgesvd so that you don’t have to pass it in from python. Exactly how f2py determines the input/output signature is explained here (there are three ways to do it, I prefer the third).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.