~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to src/array.pmt

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C -*-  */
 
2
/* 
 
3
   IGraph library.
 
4
   Copyright (C) 2006  Gabor Csardi <csardi@rmki.kfki.hu>
 
5
   MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
 
6
   
 
7
   This program is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU General Public License as published by
 
9
   the Free Software Foundation; either version 2 of the License, or
 
10
   (at your option) any later version.
 
11
   
 
12
   This program is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU General Public License for more details.
 
16
   
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with this program; if not, write to the Free Software
 
19
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA 
 
20
   02110-1301 USA
 
21
 
 
22
*/
 
23
 
 
24
#include "types.h"
 
25
 
 
26
int FUNCTION(igraph_array3,init)(TYPE(igraph_array3) *a, long int n1, long int n2, 
 
27
                                 long int n3) {
 
28
  int ret;
 
29
  ret=FUNCTION(igraph_vector,init)(&a->data, n1*n2*n3);
 
30
  a->n1=n1;
 
31
  a->n2=n2;
 
32
  a->n3=n3;
 
33
  a->n1n2=n1*n2;
 
34
  
 
35
  return ret;
 
36
}
 
37
 
 
38
void FUNCTION(igraph_array3,destroy)(TYPE(igraph_array3) *a) {
 
39
  FUNCTION(igraph_vector,destroy)(&a->data);
 
40
}
 
41
 
 
42
long int FUNCTION(igraph_array3,size)(const TYPE(igraph_array3) *a) {
 
43
  return (a->n1n2) * (a->n3);
 
44
}
 
45
 
 
46
long int FUNCTION(igraph_array3,n)(const TYPE(igraph_array3) *a, long int idx) {
 
47
  switch (idx) {
 
48
  case 1: return a->n1;
 
49
    break;
 
50
  case 2: return a->n2;
 
51
    break;
 
52
  case 3: return a->n3;
 
53
    break;
 
54
  }
 
55
  return 0;
 
56
}
 
57
 
 
58
int FUNCTION(igraph_array3,resize)(TYPE(igraph_array3) *a, long int n1, long int n2, 
 
59
                                   long int n3) {
 
60
  int ret=FUNCTION(igraph_vector,resize)(&a->data, n1*n2*n3);
 
61
  a->n1=n1;
 
62
  a->n2=n2;
 
63
  a->n3=n3;
 
64
  a->n1n2=n1*n2;
 
65
  
 
66
  return ret;
 
67
}
 
68
 
 
69
void FUNCTION(igraph_array3,null)(TYPE(igraph_array3) *a) {
 
70
  FUNCTION(igraph_vector,null)(&a->data);
 
71
}
 
72
 
 
73
BASE FUNCTION(igraph_array3,sum)(const TYPE(igraph_array3) *a) {
 
74
  return FUNCTION(igraph_vector,sum)(&a->data);
 
75
}
 
76
 
 
77
void FUNCTION(igraph_array3,scale)(TYPE(igraph_array3) *a, BASE by) {
 
78
  FUNCTION(igraph_vector,scale)(&a->data, by);
 
79
}
 
80
 
 
81
void FUNCTION(igraph_array3,fill)(TYPE(igraph_array3) *a, BASE e) {
 
82
  FUNCTION(igraph_vector,fill)(&a->data, e);
 
83
}
 
84
 
 
85
int FUNCTION(igraph_array3,update)(TYPE(igraph_array3) *to, 
 
86
                                   const TYPE(igraph_array3) *from) {
 
87
  IGRAPH_CHECK(FUNCTION(igraph_array3,resize)(to, from->n1, from->n2, from->n3));
 
88
  FUNCTION(igraph_vector,update)(&to->data, &from->data);  
 
89
  return 0;
 
90
}