Issue with older code in which arrays are misrepresented as sparse

조회 수: 5 (최근 30일)
Starting with Matlab 2010 and continuing through the current version (2013), some older code than ran cleanly on all prior versions fails to run because some 2 dimensional arrays are returned from subroutines in sparse representation, even though the code does not ask for that. I have several questions: 1. Has anybody else seen this before? 2. Does anybody know what causes it? 3. Is there a fix? I've started to go through my code and specify that all of these matrices are full, but that is cumbersome and seems like a brute force approach.
Thanks for any feedback!

채택된 답변

Mark Slifstein
Mark Slifstein 2013년 8월 2일
편집: Mark Slifstein 2013년 8월 2일
OKAY, figured it out: The program has multiple calls to lsqnonlin which is in the optimization toolbox. One of the computed values that is returned by lsqnonlin is the jacobian matrix. The jacobian is now returned in sparse format (it didn't used to be in earlier versions of the toolbox). All subsequent computations using the jacobian get coerced to be sparse, and some of these are then used as input arguments to fprintf, which doesn't accept sparse input. So, a fix for my problem is to set the jacobian to full. There is also a parameter that can be passed to lssqnonlin called JacobPattern, which sets the sparsity pattern of the jacobian matrix. Its default is full density, but as best as I can tell, it returns the variable in sparse format even if it is nonzero in all components. Thanks, Jan and Sean, for your input.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2013년 8월 2일
편집: Sean de Wolski 2013년 8월 2일
  1. No. Are the data identical and code paths the same?
  2. What functions are doing this? (I might recommend contacting support!)
  3. if issparse(X); X = full(X); end
  댓글 수: 2
Mark Slifstein
Mark Slifstein 2013년 8월 2일
Thanks for your response. Yes, the identical program runs on 2008b and older versions. I originally started to do what you suggest, which is to explicitly declare each matrix as full, but as the code is large and sprawling, there are hundreds of instantiations and I will be tracking it down for years, so was hoping for a global solution.
Sean de Wolski
Sean de Wolski 2013년 8월 2일
Contact support with an example piece of code that reproduces the issue in an old v. new release with the exact same data.

댓글을 달려면 로그인하십시오.


Jan
Jan 2013년 8월 2일
It is hard to guess the cause without seeing any detail of the code. Could you post a relevant part of the code which reproduces the problem?
Why and where does Matlab fail, when some inputs are sparse?

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by