COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Vectorize procedure

• Email
• Follow

```Hi,
I'm vectorizing a procedure in order to delete three for loops and
increase the speed.
I have to calculating the interpolation on a regular grid.
newy=interpol(y,x,newx,/spline)
in the loop manner  for each index of the loop  there are  three
different arrays .
in the vectorize manner I have three 3D matrices, But I do not found a
way to calculate the interpolation matrix.
Any one have suggestions?

Thanks

Romolo
```
 0
Reply 12/10/2009 2:57:52 PM

See related articles to this posting

```In article
Romolo Politi <romolo.politi@gmail.com> wrote:

> Hi,
> I'm vectorizing a procedure in order to delete three for loops and
> increase the speed.
> I have to calculating the interpolation on a regular grid.
> newy=interpol(y,x,newx,/spline)
>  in the loop manner  for each index of the loop  there are  three
> different arrays .
> in the vectorize manner I have three 3D matrices, But I do not found a
> way to calculate the interpolation matrix.
> Any one have suggestions?
>
> Thanks
>
> Romolo

I'm afraid that you have not clearly explained your problem.  Are you
trying to do 3-D cubic spline interpolation?  As far as I know,
standard IDL does not contain a multi-dimensional spline interpolation
procedure, only the 1-D functionality available in INTERPOL, SPLINE, and
SPL_INTERP.  You can do vectorized multi-dimensional *linear* interpolation
by using INTERPOLATE.

The Advanced Math and Statistics package (extra cost) includes the IMSL
spline interpolation functions.  You can view the help files and
see if that is what you need.

http://127.0.0.1:60523/help/index.jsp

Ken Bowman
```
 0
Reply Kenneth 12/10/2009 3:25:13 PM

```On 10 Dic, 16:25, "Kenneth P. Bowman" <k-bow...@null.edu> wrote:
> In article
> =A0Romolo Politi <romolo.pol...@gmail.com> wrote:
>
> > Hi,
> > I'm vectorizing a procedure in order to delete three for loops and
> > increase the speed.
> > I have to calculating the interpolation on a regular grid.
> > newy=3Dinterpol(y,x,newx,/spline)
> > =A0in the loop manner =A0for each index of the loop =A0there are =A0thr=
ee
> > different arrays .
> > in the vectorize manner I have three 3D matrices, But I do not found a
> > way to calculate the interpolation matrix.
> > Any one have suggestions?
>
> > Thanks
>
> > Romolo
>
> I'm afraid that you have not clearly explained your problem. =A0Are you
> trying to do 3-D cubic spline interpolation? =A0As far as I know,
> standard IDL does not contain a multi-dimensional spline interpolation
> procedure, only the 1-D functionality available in INTERPOL, SPLINE, and
> SPL_INTERP. =A0You can do vectorized multi-dimensional *linear* interpola=
tion
> by using INTERPOLATE.
>
> The Advanced Math and Statistics package (extra cost) includes the IMSL
> spline interpolation functions. =A0You can view the help files and
> see if that is what you need.
>
> =A0 =A0http://127.0.0.1:60523/help/index.jsp
>
> Ken Bowman

Sorry for the not clarity.
my situation is
x=3Dfltarr(3200,201,201)
y=3Dfltarr(3200,201,201)
newx=3Dfltarr(799,201,201)
newy=3Dfltarr(799,201,201)
for i=3D0,200 do begin
for j=3D0,200 do begin
newy[*,i,j]=3Dinterpol(y[*,i,j],x[*,i,j],newx[*,i,j],/SPLine)
endfor
endfor

I like vectorize this loop.

Thanks, and sorry again

Romolo Politi
```
 0
Reply Romolo 12/10/2009 6:03:02 PM

```In article
Romolo Politi <romolo.politi@gmail.com> wrote:

> Sorry for the not clarity.
> my situation is
> x=fltarr(3200,201,201)
> y=fltarr(3200,201,201)
> newx=fltarr(799,201,201)
> newy=fltarr(799,201,201)
> for i=0,200 do begin
>   for j=0,200 do begin
>     newy[*,i,j]=interpol(y[*,i,j],x[*,i,j],newx[*,i,j],/SPLine)
>   endfor
> endfor

You are doing ~40,000 separate spline fits.  I don't think there is
any way to vectorize this, as each fit is an independent problem.
Spline fitting is a coupled problem, so you cannot, for example, simply
string your segments together into one long fit.

If the newx[*,i,j] are the same for all i and j, you can probably get
a significant speed-up by calling SPL_INIT once and then calling
SPL_INTERP for each i and j.  Since you are storing newx separately
for each i and j, I gather this is not the case.

Your program is accessing memory efficiently, but you will get a small
speed up by saying

newy[0,i,j]=interpol(y[*,i,j],x[*,i,j],newx[*,i,j],/SPLine)

You might also try the other built in spline functions:  SPLINE,
SPLINE_P, SPL_INIT and SPL_INTERP to see whether one is faster.

Finally, I notice that you are downsampling your data substantially.
Are you sure you really need to use a spline fit to do that?

Ken Bowman
```
 0
Reply Kenneth 12/10/2009 8:00:41 PM

```On Dec 10, 3:00=A0pm, "Kenneth P. Bowman" <k-bow...@null.edu> wrote:
> In article
> =A0Romolo Politi <romolo.pol...@gmail.com> wrote:
>
> > Sorry for the not clarity.
> > my situation is
> > x=3Dfltarr(3200,201,201)
> > y=3Dfltarr(3200,201,201)
> > newx=3Dfltarr(799,201,201)
> > newy=3Dfltarr(799,201,201)
> > for i=3D0,200 do begin
> > =A0 for j=3D0,200 do begin
> > =A0 =A0 newy[*,i,j]=3Dinterpol(y[*,i,j],x[*,i,j],newx[*,i,j],/SPLine)
> > =A0 endfor
> > endfor
>
> You are doing ~40,000 separate spline fits. =A0I don't think there is
> any way to vectorize this, as each fit is an independent problem.
> Spline fitting is a coupled problem, so you cannot, for example, simply
> string your segments together into one long fit.
>
> If the newx[*,i,j] are the same for all i and j, you can probably get
> a significant speed-up by calling SPL_INIT once and then calling
> SPL_INTERP for each i and j. =A0Since you are storing newx separately
> for each i and j, I gather this is not the case.
>
> Your program is accessing memory efficiently, but you will get a small
> speed up by saying
>
> =A0 =A0newy[0,i,j]=3Dinterpol(y[*,i,j],x[*,i,j],newx[*,i,j],/SPLine)
>
> You might also try the other built in spline functions: =A0SPLINE,
> SPLINE_P, SPL_INIT and SPL_INTERP to see whether one is faster.
>
> Finally, I notice that you are downsampling your data substantially.
> Are you sure you really need to use a spline fit to do that?
>
> Ken Bowman

You might be able to fake something in the "stringing the segments
together" vein by putting some padding in between the segments that
does a linear interpolation between the endpoint of one segment and
the beginning of the next, enough padding to make the last old segment
and first new segment independent. Of course, you'll get a different
answer for those end segments because of that padding than if they
didn't exist, so that may not work depending on how much those points
are offset, but it should at least be better than sticking them next
to each other. What boundary conditions does INTERPOL use with spline
fits? Maybe you can design padding that effectively gives you the same
boundary conditions?

-Jeremy.
```
 0
Reply Jeremy 12/11/2009 4:20:13 PM

4 Replies
234 Views

Similar Articles

12/10/2013 9:52:46 PM
page loaded in 84203 ms. (0)

Similar Artilces:

sorting a vector segment of a vector<string>
How does one sort only part of a vector of strings i.e vector<string>. sort ( xx,xx.begin(),xx.end() ) sorts the full xx . I have a application in which i have resized xx to a good size , but i want to sort only the top which contains my strings. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] On Jul 21, 10:16 am, TomCat <uselesso...@gmail.com> wrote: > How does one sort only part of a vector of strings i.e > vector<string>. > sort ( xx,xx.begin(),xx.end() ) sorts the fu...

Covariant vectors
Hi all, I've been looking for a way to simulate covariant, const, vectors for some time. From another thread, it seems as though vectors are supposed to be allocated contiguously. So I wonder if the technique below is safe and legal in the general case. In particular, I'm not sure if given virtual or multiple inheritance, the pointers would be adjusted properly. // Foo.hpp struct Base { int a; }; void Foo(Base*, size_t); // Foo.cpp #include <iostream> #include "Foo.hpp" void Foo(Base* array, size_t size) { for (size_t i = 0; i < size; ++i) s...

Static vector
I have a question about static objects. #include <iostream> #include <vector> using namespace std; void f(){ static vector<int> v; v.push_back(1); cout << v.size() << endl; } int main(){ for(int i = 0; i < 1000; i++) { f(); } } where actually does the compiler stores the vector<int> v? And after every internal resize does the memory taken by static vector grows. Or does the compiler only stores the pointer to vector<int> v. -- [ See http://www.gotw.ca/resources/clcm.htm for info ...

Re: SAS VECTOR
Simply put, the data vector is a line of data, or a record, or an observation. It's useful to understand when merging or setting multiple data sets. The SAS onlinedoc says "The PDV contains all the variables in the input data set, the variables created in DATA step statements, and the two variables, _N_ and _ERROR_, that are automatically generated for every DATA step." http://v8doc.sas.com/sashtml/lrcon/z0961108.htm Paul Choate DDDS Data Extraction On Fri, 22 Aug 2003 07:14:44 GMT, Yanal <fake@BYU.EDU> wrote: >What is the SAS vector, and where can one learn about...

Vectored Interrupt Fetch
Hi, I'm studying interrupt logic at the moment, and I was just wondering how well vectored (via address table) interrupt handling is performed. For instance when the interrupt vector table is allowed to be located in memory at any address, it would seem to me that there could be numerous clock cycles involved to fetch the address from memory. Are the memory locations loaded into and locked in the cache for performance ? Why not just have a bunch of special registers (eg 64) in the cpu that store interrupt routine addresses ? Why is the vector table relocatable ? Thanks, Rob ...

Magnitude of a 3d vector
There was a need for quick and dirty approximation of the magnitude of the 3-dimensional vector (x,y,z). This is what worked best: Let x = max(x,y,z) Then magnitude ~ x + 0.25*(y+z) Accuracy ~ 13% Interestingly, this provides for better accuracy then the sequential use of the two 2d approximations (see Lyons's "Root of all evils"). Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com Perhaps there are better choices than .25. Better, of course, would depend on the criterion of goodness. Grant Griffin computed several "optim...

std::vector and array
Dear all, Could someone please let me know what is wrong with the following: #include <vector> int main() { typedef double (OriginType)[3]; std::vector< OriginType > OriginArray; // OriginArray.reserve( 1 ); OriginArray.resize( 1 ); // does not compile return 0; } this code does not compile using g++-4.4 Thanks ! On 01/02/2011 18:40, mathieu wrote: > Dear all, > > Could someone please let me know what is wrong with the following: > > #include<vector> > > int main() > { > typedef double (Origin...

Vectors: not worthless? (out of curiosity)
Hi, I'm a C++="C with classes" kind of guy and was wondering if anyone felt like making the case that STL Vectors are in any way better than my home-brewed, memmove()-heavy dynamic array class (ignoring the it's-a-standard point). Thanks, Jay "Jay" <twentycavities@hotmail.com> wrote in message news:Og7Va.5689\$IQ2.320@fe1.columbus.rr.com... > Hi, > I'm a C++="C with classes" kind of guy and was wondering if anyone felt like > making the case that STL Vectors are in any way better than my home-brewed, > memmove()-heavy dynamic ar...

Vectorize multiple polyfits
Hi, I have a 3D array M, e.g. of size 100x100x10, and I want to fit each "column" M(x, y, :) (for x=1:100, y=1:100) to a polynomial of degree 2 (x values being in a constant vector v), and store the 3 coefficients of the fit in a 100x100x3 array N. Of course I could do something like for x = 1:100 for y = 1:100 N(x, y, :) = polyfit(v, M(x, y, :), 2) end end but I'd like to know if there's a way to vectorize this piece of code. Thanks in advance, Antony A=vander(v); Mp=permute(M,[3 1 2]); Mfit=ipermute( A*(A\Mp) , [3 1 2]); On 18 mar, 13:41, &...

book on vectorization for multimedia extensions
Intel Press has published the following book on compiler optimizations for multimedia extensions: A.J.C. Bik. The Software Vectorization Handbook. Applying Multimedia Extensions for Maximum Performance. Intel Press, June, 2004. <http://www.intel.com/intelpress/sum_vmmx.htm?iid=ipr+vmmxcompgroup&> Description: The growing popularity of multimedia extensions has renewed the interest in vectorizing compilers. "The Software Vectorization Handbook" provides a detailed overview of compiler optimizations that convert sequential code into a form that best exploits multimedia exte...

Eigen values and vectors #2
I would like to know which is the method used by Matlab to calculate the eigen values and vectors. see help eig Diego Corredor wrote: > > > I would like to know which is the method used by Matlab to > calculate > the eigen values and vectors. For even more info: doc eig "Ri" <ri@ozono.pe.u-tokyo.ac.jp> wrote in message news:eee8dc4.0@webx.raydaftYaTP... > see > help eig > > Diego Corredor wrote: > > > > > > I would like to know which is the method used by Matlab to > > calculate > > the eigen values and vectors. ...

How to vectorize and avoid this for loop to speed up?
Hi all, When inside a loop, there is a vector operator(r and p) already, how to further vectorize it along another dimension (for "u" and "us")? Here is my code: --------------- tmp=zeros(size(us)); %pre-allocation for i=1:length(us); u=us(i); t7=u+b*p(:); tmp(i)=exp(-u*a- r(:).'*t7(:) ); end; --------------- Let me explain. "us" is a vector. I generate "tmp" the same length as "us". For each element of "us", I compute an element for "tmp". "p" and "r" are vectors of equal length...

Event Procedure to call a Report
Hi, I am trying to print address labels. I have a form which asks for the user to input the first name, middle initial, and last name. On the button click to print the label, I have an event procedure which is called. The problem seems to be having two different reports in the same procedure. Basically, I want to check if the user has typed in a middle initial. If no middle initial is typed in, I want to load the report with only the first and last name. However, if the user puts a first name, middle initial, and last name, I want to load a different report which filters the results using th...

[LogoForum] Re: Sprites to vectors
The message below is being cross-posted from LogoForum. Dear Robin, svg.lgo procedures are "buried" (please see the MSWLogo Reference Manual) and are loaded by svg-examples.lgo with load "svg.lgo. Guido Gay --- In LogoForum@yahoogroups.com, "rireeves2004" <rireeves@t...> wrote: > > Hi! > > I'm trying to follow the messages about converting sprites to vector > graphics. I have downloaded the LogoSVG.zip file and had a look at > figuga.html which is great and at svg-examples and yehuda01. > Although svg.lgo is 14k I can't see any p...

How to make matrix coordinates vectors?
As we know that we can make the matrix coordinates for accumarray: V = 101:112; V=V(:); rowsubs = [1 3 3 2 3 1 2 2 3 3 1 2]; rowsubs = rowsubs(:); colsubs = [3 4 2 1 4 3 4 2 2 4 3 4]; colsubs = colsubs(:); pagsubs = [1 1 2 2 1 1 2 1 1 1 2 2]; pagsubs = pagsubs(:); A = accumarray([rowsubs, colsubs, pagsubs], V) How can we use this for matrix coordinates index? Like this: x=(1:10); x=x(:); y=round(10*rand(1,10)); y(b==0)=1; y=y(:); m=rand(10); Now, can we use 'x' 'y' as the coordinates of 'm'? m(x,y) kind of thing? Thanks. Apple I just found a way to do this: ind=su...

turn result of imread into vector field
Hi I'd like to read in image into my program using imread and then vectorize the image. The many 3 dimensional sample data makes it look easy when you define your own x,y,z. But how is this done for imread? Thanks in advance To directly convert into a vector, you can use colon operator also, or first convert it into grayscale image and then use colon operator. ImgVec= img(:); Or GrayImg=rgb2gray(img); imgVec=GrayImg(:); Or you can use reshape operator also. - Parag Shridhar Chandakkar. ...

Best practices in putting procedures in modules
Hi all, suppose to have a TYPE (say TYPE a), its definition (TYPE a ... END TYPE a), and a lot of related procedures. They are intended to go in a library file (say my_lib.a). These procedures may be classified as: 1) access procedures; 2) procedures manipulating instances of TYPE(a) alone; 3) as above, but requiring help from other-than-my_lib.a libraries (for example BLAS); 4) procedures requiring other TYPEs defined in other modules (USE MODULE ....) Such modules already are in my_lib.a; 5) as above, but requiring help from other-than-my_lib.a libraries (for example BLAS). So far, ...

Need to extract vector data from PDF
Hi, I'm looking for an SDK (or command line program) that will allow me to extract text, raster images, and geometric/vector data from a PDF. Besides Adobe's SDK and PDFNet (http://www.pdftron), is there anything else? I guess extracting to any CAD format (DGN, DWG, DXF) would also work. Being able to extract metadata (marked content) would also be a big plus. Thanks, Dave Dave, Have a look at www.visual-integrity.com. Our pdf2vector software is available in command line and API versions. It can convert to DXF and other vector formats, extract raster images, extract text. ...

Ultra 20 Support Procedure Question
On Aug 31, I ordered the "Free Developer Workstation" Promotional Ultra 20 with 3 years Silver Service Plan via www.sun.com. I received the Ultra 20 on Sept 17 and on Sept 26 I received a statement indicating that my credit card was charged for the first year support on Sept 1, but nothing else about support. What is the procedure to get the service activated ? Will I eventually receive additional info and a contract number from Sun, or due I have to initiate something ? In article <_RA1f.404655\$x96.309482@attbi_s72>, Hugh Coomes <hcoomes@insightbb.com> wrote: >Wh...

3D vector rotation to the Z axis
I would like to rotate and arbitrary 3D vector to be aligned with the Z axis. I can translate and scale the vector but I can not find a formula to create the rotation matrix to perform the rotation. It sounds simple but I can't seem to find one. Thanks On Dec 14, 1:11=A0am, MartyL <mlandsf...@yahoo.com> wrote: > I would like to rotate and arbitrary 3D vector to be aligned with the > Z axis. I can translate and scale the vector but I can not find a > formula to create the rotation matrix to perform the rotation. It > sounds simple but I can't seem to find one...