Article View: adobe.postscript.programming
Article #25Re: postscript & sparse matrices: howto?
From: Peter Davis
Date: Tue, 03 Feb 2009 11:38
Date: Tue, 03 Feb 2009 11:38
52 lines
3139 bytes
3139 bytes
On Jan 31, 11:03ย am, Nico_Schlรถm...@adobeforums.com wrote:
> hi!
>
> i'm dealing with matrices here and want to plot its value into postscript. in fact, i just need a black spot where a matrix entry is not zero, white everywhere else. easy, isn't it?
>
> particulary, my matrices have very few non-zero entries, so the ps file would only have a few black spots here and there.
>
> now, what's the best way to write this in postscript? the first thing i tried was the image environment: works well as soon as you got used to the syntax, but the big disadvantage for me was that i have to explicitly code all the white pixels, so the eps file gets a lot bigger than needed (it feels).
>
> the second thing i tried was defining a small "draw tiny box" command, then "move to" the non-zero spots, and evoke the function.
> that's better then the image way (the files are a lot smaller), but it still feels like a hack somehow.
>
> do you have any hints or suggestions for the issue? are there any commands or environment that would be better suited?
>
> all hints appreciated!
>
> cheers,
> nico
PostScript is, in some ways, a perfect language for sparse matrices.
You can simply use a dictionary. A dictionary key could be anything,
including a number. So you could store your matrix elements with
something like:
/mysparsemtx 100 dict def
/key x 1024 mul y add def
mysparsemtx key 1 put
Now wherever you have a "1" stored, you can treat that as a black
spot. You can traverse the whole matrix with
mysparsemtx {
pop % You can throw away the "1" since every entry has a "1" stored
dup 1024 mod /y exch def 1024 div /x exch def % unpack the original
x and y
% do whatever you want with x and y
} forall
NOTE: I haven't tested this code, but this is the gist of the
approach.
-pd
Technical Details
Message-ID:
<01755d63-b366-46ca-89d6-2add560fde9f@d32g2000yqe.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!d32g2000yqe.googlegroups.com!not-for-mailReferences:
<59b7be49.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: 10c61a,527ad8c75b709cef X-Google-Attributes: gid10c61a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!d32g2000yqe.googlegroups.com!not-for-mail From: Peter Davis <pdavis.pageflex@gmail.com> Newsgroups: adobe.postscript.programming Subject: Re: postscript & sparse matrices: howto? Date: Tue, 3 Feb 2009 03:38:38 -0800 (PST) Organization: http://groups.google.com Lines: 53 Message-ID: <01755d63-b366-46ca-89d6-2add560fde9f@d32g2000yqe.googlegroups.com> References: <59b7be49.-1@webcrossing.la2eafNXanI> NNTP-Posting-Host: 98.217.207.228 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1233661118 2433 127.0.0.1 (3 Feb 2009 11:38:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 3 Feb 2009 11:38:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d32g2000yqe.googlegroups.com; posting-host=98.217.207.228; posting-account=bvh45QoAAADSBAyo2WJ2isUDSW-UAyEn User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,gzip(gfe),gzip(gfe)