help-octave
[Top][All Lists]
Advanced

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

Structures and tensors


From: Cédric Févotte
Subject: Structures and tensors
Date: Tue, 01 Aug 2006 17:55:06 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060607 Debian/1.7.12-1.2

Hi everyone,

What are the general recommandations about the use of structures and tensors in Octave ? Understand, is it recommanded to avoid them ?

What led to my question is the following piece of code, in which I copy the vector ones(n,1) sequentially into a variable, which is either
1) a matrix of size n x n_iter,
2) a matrix of size n x n_iter contained in the field of a structure,
3) a tensor of size n x n_iter x 1,
4) a tensor of size n x n_iter x 1 contained in the field of a structure

The results are striking (obtained either on octave 2.1 or 2.9 under Linux Debian) :

Elapsed time is 0.071320 seconds.
Elapsed time is 0.324188 seconds.
Elapsed time is 3.279373 seconds.
Elapsed time is 3.327034 seconds.

Any comments ?

All the best

Cedric

%%% Code %%%

n_iter = 10000;
n=50;

%%% 1: Matrix of size n x n_iter %%%
E=zeros(n,n_iter);

tic
for iter=1:n_iter
  E(:,iter)=ones(n,1);
end
toc

%%% 2: Matrix in Structure %%%
cur = struct("E",zeros(n,n_iter));

tic
for iter=1:n_iter
  cur.E(:,iter)=ones(n,1);
end
toc

%%% 3: Tensor of size n x n_iter x 1  %%%
E=zeros(n,n_iter,1);

tic
for iter=1:n_iter
  E(:,iter,1)=ones(n,1);
end
toc

%%% 4: Tensor in Structure %%%
cur = struct("E",zeros(n,n_iter,1));

tic
for iter=1:n_iter
  cur.E(:,iter,1)=ones(n,1);
end
toc

%%% End Code %%%

--
Dr Cédric Févotte
Researcher
Mist Technologies
204 rue de Crimée, 75019 Paris, France
Tel: +33 1 55 26 42 31 - Fax: +33 1 55 26 42 03
Web: http://persos.mist-technologies.com/~cfevotte


reply via email to

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