octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FYI: sparse indexed assignment rewritten


From: David Bateman
Subject: Re: FYI: sparse indexed assignment rewritten
Date: Fri, 16 Apr 2010 17:18:29 +0200
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

Jaroslav Hajek wrote:
On Fri, Apr 16, 2010 at 1:02 PM, David Bateman <address@hidden> wrote:
Jaroslav Hajek wrote:
On Wed, Apr 14, 2010 at 3:44 PM, John W. Eaton <address@hidden> wrote:

On 13-Apr-2010, Jaroslav Hajek wrote
   | 3. simple grep query shows that the interpreter uses nzmax at
| suspiciously many places. I bet some of those usages are wrong and
| should be nnz, but it requires individual approach. So get ready for
| mysterious crashes, just in case.

I guess we need to look at all nzmax uses and decide whether they
should be nnz instead.  Are there any simple rules for when nzmax is
required?

nzmax is now (as it should have always been) just the amount of space
allocated for nz elements. So probably anything that merely reads the
matrix wants to use nnz(). An exception is conversion (conversions
should preserve nzmax because of spalloc), but I think I already
handled that.


I started to look at this and have a question. For the octave file formats
do we want to save the sparse matrix in a way that preserves the values of
nzmax if it is different than nnz? If we do, then we need to change the
format as only one of these values is currently saved. A similar issue
exists for the matlab file format.. They save the value of nzmax in the tag
and nnz can be derived from the element length (given in bytes). However as
I no longer have access to matlab I'm unsure if matlab uses this to save the
value of nzmax or not.. What does

s = spalloc (10,10,10);
save -v6 f.mat s
clear all
load f.mat
nzmax(s)

give in a recent version of matlab?

Cheers
David


I don't see much reason to save nzmax > nnz. nzmax is tightly related
to memory, not to the actual value of the matrix. I suppose that when
saving, you want to save only as much data as needed. I'd say let's
save just nnz and the valid data, which is a non-disturbing change. If
anyone can bring forward arguments why saving also nzmax is desired,
it can be discussed and possibly changed.

regards

Ok, then consider the attached changeset which has the following properties

- nzmax is preserved for transfers between oct and mex APIs
- nzmax is lost when saving to octave file formats
- libraries like CHOLMOD, etc use the variable name nzmax internally for nnz and these usages have been left
- the Fsparse now respects the nzmax argument when given
- ls-mat5.cc not yet treated as I need to know what matlab gives for

s = spalloc (10,10,10);
save -v6 f.mat s
clear all
load f.mat
nzmax(s)

- Other uses of nzmax changed to nnz

So only loading and saving of matlab files should now cause problems when nzmax doesn't equal nnz. The remaining uses of nzmax except in ls-mat5.cc should now be correct.

Cheers
David

diff --git a/scripts/plot/__go_draw_axes__.m b/scripts/plot/__go_draw_axes__.m
--- a/scripts/plot/__go_draw_axes__.m
+++ b/scripts/plot/__go_draw_axes__.m
@@ -23,9 +23,9 @@
 
 ## Author: jwe
 
-function __go_draw_axes__ (h, plot_stream, enhanced, mono, implicit_margin)
+function __go_draw_axes__ (h, plot_stream, enhanced, mono, implicit_margin, 
bg_is_set)
 
-  if (nargin >= 4 && nargin <= 5)
+  if (nargin >= 4 && nargin <= 6)
 
     showhiddenhandles = get (0, "showhiddenhandles");
     unwind_protect
@@ -1551,10 +1551,18 @@
        elseif (is_image_data (i))
          if (! is_image_data (i-1))
            fputs (plot_stream, "; ");
+            if (bg_is_set)      
+              fputs (plot_stream, "unset obj 1; \\\n");
+              bg_is_set = false;
+            endif
          endif
           fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd,
                   usingclause{i}, titlespec{i}, withclause{i});
        elseif (is_image_data (i-1))
+          if (bg_is_set)      
+            fputs (plot_stream, "unset obj 1; \\\n");
+              bg_is_set = false;
+            endif
          fprintf (plot_stream, "%s \"-\" binary format='%%float64' %s %s %s 
\\\n", plot_cmd,
                   usingclause{i}, titlespec{i}, withclause{i});
        else
@@ -1593,6 +1601,11 @@
     if (view_map)
       fputs (plot_stream, "unset view;\n");
     endif
+    
+    if (bg_is_set)      
+      fputs (plot_stream, "unset obj 1;\n");
+      bg_is_set = false;
+    endif
 
     fflush (plot_stream);
 
diff --git a/scripts/plot/__go_draw_figure__.m 
b/scripts/plot/__go_draw_figure__.m
--- a/scripts/plot/__go_draw_figure__.m
+++ b/scripts/plot/__go_draw_figure__.m
@@ -97,21 +97,18 @@
                     axes_position_on_page = orig_axes_position .* 
paper_position([3, 4, 3 ,4]);
                     axes_position_on_page(1:2) = axes_position_on_page(1:2) +  
paper_position(1:2);
                     set (kids(i), "position", axes_position_on_page);
-                    __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, 
implicit_margin);
+                    __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, 
implicit_margin, bg_is_set);
                   else
                     ## Return axes "units" and "position" back to their 
original values.
-                    __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, 
implicit_margin);
+                    __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, 
implicit_margin, bg_is_set);
                   endif
                   unwind_protect_cleanup
                   set (kids(i), "units", orig_axes_units);
                   set (kids(i), "position", orig_axes_position);
+                  bg_is_set = false;
                   if (fg_is_set)
                     fputs (plot_stream, "unset obj 2\n");
                   endif
-                  if (bg_is_set)
-                    fputs (plot_stream, "unset obj 1\n");
-                    bg_is_set = false;
-                  endif
                 end_unwind_protect
               otherwise
                 error ("__go_draw_figure__: unknown object class, %s", type);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]