View Javadoc
1   /*
2    * Copyright 2009 Ange Optimization ApS
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package eu.simuline.octave.type;
17  
18  /**
19   * Represents a complex matrix. 
20   */
21  // **** seems as if could be more close to OctaveDouble 
22  // implementing AbstractGenericMatrix or maybe even GenericMatrix 
23  // caution with OctaveCell using AbstractGenericMatrix
24  // using also an according reader 
25  public final class OctaveComplex implements OctaveObject {
26  
27      private final OctaveDouble real;
28  
29      private final OctaveDouble imag;
30  
31      /**
32       * @param size
33       */
34      public OctaveComplex(final int... size) {
35          this.real = new OctaveDouble(size);
36          this.imag = new OctaveDouble(size);
37      }
38  
39      /**
40       * Copy constructor. 
41       * 
42       * @param o
43       */
44      public OctaveComplex(final OctaveComplex o) {
45          this.real = new OctaveDouble(o.real);
46          this.imag = new OctaveDouble(o.imag);
47      }
48  
49      public OctaveComplex(OctaveDouble r) {
50  	this.real = new OctaveDouble(r);
51  	this.imag = r.zero();
52      }
53  
54      /**
55       * @param i
56       *            dimension number in 1 based numbering, 1=row, 2=column
57       * @return the size in dimension i
58       */
59      public int getSize(final int i) {
60          return this.real.getSize(i);
61      }
62  
63      /**
64       * @param pos
65       * @return the index into getReal() and getImag() for the position
66       * @see eu.simuline.octave.type.matrix.AbstractGenericMatrix#pos2ind(int[])
67       */
68      public int pos2ind(final int... pos) {
69          return this.real.pos2ind(pos);
70      }
71  
72      /**
73       * @param value
74       * @param pos
75       */
76      public void setReal(final double value, final int... pos) {
77          this.real.set(value, pos);
78          this.imag.resizeUp(pos);
79      }
80  
81      /**
82       * @param pos
83       * @return the real value stored at pos
84       */
85      public double getReal(final int... pos) {
86          return this.real.get(pos);
87      }
88  
89     /**
90       * @param value
91       * @param pos
92       */
93      public void setImag(final double value, final int... pos) {
94          this.real.resizeUp(pos);
95          this.imag.set(value, pos);
96      }
97  
98      /**
99       * @param pos
100      * @return the imaginary value stored at pos
101      */
102     public double getImag(final int... pos) {
103         return this.imag.get(pos);
104     }
105 
106     @Override
107     public OctaveComplex shallowCopy() {
108         return new OctaveComplex(this);
109     }
110 
111 }