[Scilab-users] vectoriztion and sets of data
Adrien Vogt-Schilb
vogt at centre-cired.fr
Fri Nov 23 09:54:00 CET 2012
On 22/11/2012 22:59, Paul Carrico wrote:
>
> Thanks for your suggestion ; it's is interesting for another specific
> development... unfortunately I don't think I cannot adapt that code
> for my project !
>
> Indeed I need to work on sets of data (n rows of data at the same time
> to select, to rearrange, to transform, to mean, etc. ...) on matrix on
> size on X*n rows (X may be 100 000 ... ) ; currently I use loops as
> described above ...
>
> ... the issue is to optimize the following line through vectorized "i" index:Search = max(abs(C([i. * 8 - 7 :i. * 8],:)))
Hi
Right.
Well a trivial improvment is still :
D=zeros((nr/8),1);
fori=1:(nr/8)
D=max(abs(C((8*(i-1)+1):(8*i),:)))>0; //oh, that's what you meant
with "ok with the if"
end
But you want to get rid of the loop I gess.
Do you actually build the C matrix yourself as in the example?
I believe your example is equivalent to:
A=rand(8,6);
B=zeros(8,6);
C=[A;A;B;A;B;B;A];
D=[max(abs(A))>0; max(abs(A))>0; max(abs(B))>0; max(abs(A))>0;
max(abs(B))>0; max(abs(B))>0; max(abs(A))>0]
or better to
isA = max(abs(A))>0;
isB =max(abs(B))>0;
C=[isA; isA; isB; isA; isB; isB; isA]
in other words: the idea is to write D while you build C, not once C is
built entirely. Does that make sense for your actual code?
> Si let 's rack one's brains ...
>
> Thanks
>
> Paul
>
> *De :*users-bounces at lists.scilab.org
> [mailto:users-bounces at lists.scilab.org] *De la part de* Adrien Vogt-Schilb
> *Envoyé :* jeudi 22 novembre 2012 16:12
> *À :* International users mailing list for Scilab.
> *Objet :*Re: [Scilab-users] vectoriztion and sets of data
>
> Hi again
>
> I am still not sure, but look at the output of
>
> A=rand(8,6)
>
> B=zeros(8,6)
>
> D = A > B
>
> D = bool2s (A > B)
>
> This might give you insight on how to solve your problem
> tell me if not
>
> On 22/11/2012 16:06, Paul Carrico wrote:
>
> The original code looked like ... I'm trying to optimized it (ok
> for the "if", but how to combine a set of data and vectorization
> (??? Many trials but I failed)
>
> /// initial matrix/
>
> A=rand(8,6);
>
> B=zeros(8,6);
>
> C=[A;A;B;A;B;B;A];
>
> [nr,nc]=size(C);
>
> /// original code looks like/
>
> D=zeros((nr/8),1);
>
> fori=1:(nr/8)
>
> search=max(abs(C((8*(i-1)+1):(8*i),:)));
>
> if(search>0)then
>
> D(i,1)=1;
>
> else
>
> D(i,1)=0;
>
> end
>
> end
>
> ###################################################
>
> mode(0)
>
>
>
> /// initial matrix/
>
> A = rand(8,6);
>
> B = zeros(8,6);
>
> C = [A ; A; B; A; B; B; A];
>
> [nr,nc] = size(C);
>
>
>
> /// each set of 8 rows is analysed/
>
> Search = zeros((nr/8),1);
>
> ///i = ones((nr/8),1).* 1;/
>
> i = [1:(nr/8)]';
>
> /// Search = max(abs(C((8*(i - 1) + 1):(8 * i),:)));/
>
> Search = max(abs(C([i. * 8 - 7 :i. * 8],:)))
>
> ;
>
> B = (find(Search == 0))';
>
>
>
> D = zeros((nr/8),1);
>
> D(B,2) = 1;
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20121123/b3eedcd7/attachment.htm>
More information about the users
mailing list