annotate scripts/java/org/octave/Matrix.java @ 25054:6652d3823428 stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Fri, 30 Mar 2018 09:19:05 -0400
parents 194eb4bd202b
children 00f796120a6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
1 /*
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
2
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3 Copyright (C) 2007-2018 Michael Goffioul
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
4
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
5 This file is part of Octave.
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
10 (at your option) any later version.
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
11
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
12 Octave is distributed in the hope that it will be useful, but
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
15 GNU General Public License for more details.
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
16
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
17 You should have received a copy of the GNU General Public License
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
19 <https://www.gnu.org/licenses/>.
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
20
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 package org.octave;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 import java.nio.*;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 import java.text.DecimalFormat;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 public class Matrix
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 {
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
30 private int[] dims;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
31 private Buffer data;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
32 private Object cache = null;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
34 public Matrix ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
35 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
36 this (new double[0], new int[] {0, 0});
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
37 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
39 public Matrix (double[] data)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
40 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
41 this (data, new int[] {1, data.length});
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
42 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
44 public Matrix (double[][] data)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
45 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
46 int m = data.length;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
47 int n = (m > 0 ? data[0].length : 0);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
48 int idx = 0;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
49 double[] buf = new double[m*n];
18013
501cb6a90f0f maint: Replace unnecessary tabs with spaces.
Rik <rik@octave.org>
parents: 17744
diff changeset
50
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
51 for (int j = 0; j < n; j++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
52 for (int i = 0; i < m; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
53 buf[idx++] = data[i][j];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
54 this.data = DoubleBuffer.wrap(buf);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
55 this.dims = new int[] {m, n};
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
56 this.cache = data;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
57 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
59 public Matrix (double[][][] data)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
60 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
61 int m = data.length;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
62 int n = (m > 0 ? data[0].length : 0);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
63 int p = (n > 0 ? data[0][0].length : 0);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
64 int idx = 0;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
65 double[] buf = new double[m*n*p];
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
67 for (int k = 0; k < p; k++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
68 for (int j = 0; j < n; j++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
69 for (int i = 0; i < m; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
70 buf[idx++] = data[i][j][k];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
71 this.data = DoubleBuffer.wrap(buf);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
72 this.dims = new int[] {m, n, p};
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
73 this.cache = data;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
74 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
76 public Matrix (double[] data, int[] dims)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
77 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
78 this.dims = dims;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
79 this.data = DoubleBuffer.wrap(data);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
80 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
82 public Matrix (byte[] data, int[] dims)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
83 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
84 this.dims = dims;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
85 this.data = ByteBuffer.wrap(data);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
86 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
88 public Matrix (int[] data, int[] dims)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
89 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
90 this.dims = dims;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
91 this.data = IntBuffer.wrap(data);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
92 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
94 public double[] toDouble ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
95 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
96 if (data instanceof DoubleBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
97 return ((DoubleBuffer)data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
98 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
99 throw new ClassCastException ("matrix is not of type `double'");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
100 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
102 public byte[] toByte ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
103 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
104 if (data instanceof ByteBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
105 return ((ByteBuffer)data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
106 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
107 throw new ClassCastException ("matrix is not of type `byte'");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
108 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
110 public int[] toInt ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
111 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
112 if (data instanceof IntBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
113 return ((IntBuffer)data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
114 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
115 throw new ClassCastException ("matrix is not of type `integer'");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
116 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
118 public int getNDims ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
119 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
120 return (dims == null ? 0 : dims.length);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
121 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
123 public int getDim (int index)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
124 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
125 return (dims == null || index < 0 || index >= dims.length ? -1 : dims[index]);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
126 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
128 public int[] getDims ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
129 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
130 return dims;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
131 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
133 public String getClassName ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
134 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
135 if (data instanceof DoubleBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
136 return "double";
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
137 else if (data instanceof IntBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
138 return "integer";
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
139 else if (data instanceof ByteBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
140 return "byte";
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
141 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
142 return "unknown";
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
143 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
145 public String toString ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
146 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
147 if (dims == null || data == null)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
148 return "null";
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
150 String s = "";
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
152 if (dims.length == 2 && dims[0] == 1 && dims[1] <= 5)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
153 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
154 if (data instanceof DoubleBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
155 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
156 DoubleBuffer b = (DoubleBuffer)data;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
157 DecimalFormat fmt = new DecimalFormat ("0.0000 ");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
158 for (int i = 0; i < b.capacity (); i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
159 s += fmt.format (b.get (i));
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
160 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
161 else if (data instanceof IntBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
162 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
163 IntBuffer b = (IntBuffer)data;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
164 for (int i = 0; i < b.capacity (); i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
165 s += (Integer.toString (b.get (i)) + " ");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
166 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
167 else if (data instanceof ByteBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
168 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
169 ByteBuffer b = (ByteBuffer)data;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
170 for (int i = 0; i < b.capacity (); i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
171 s += (Byte.toString (b.get (i)) + " ");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
172 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
173 s = ("[ " + s + "]");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
174 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
175 else if (dims.length == 2 && dims[0] == 0 && dims[1] == 0)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
176 s = "[ ]";
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
177 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
178 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
179 for (int i = 0; i < dims.length; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
180 if (i == 0)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
181 s = Integer.toString (dims[i]);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
182 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
183 s += (" by " + Integer.toString (dims[i]));
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
184 s = ("[ (" + s + ") array of " + getClassName () + " ]");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
185 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
187 return s;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
188 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
190 public static Object ident (Object o)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
191 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
192 System.out.println (o);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
193 return o;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
194 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
196 public boolean equals (Object value)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
197 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
198 if (value instanceof Matrix)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
199 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
200 Matrix m = (Matrix)value;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
201 if (!java.util.Arrays.equals (dims, m.dims))
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
202 return false;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
203 return data.equals (m.data);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
204 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
205 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
206 return false;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
207 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
209 public boolean isEmpty ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
210 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
211 return (data == null || dims == null || data.capacity () == 0);
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
212 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
214 public boolean isVector ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
215 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
216 return (dims.length == 1 ||
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
217 (dims.length == 2 && (dims[0] == 1 || dims[1] == 1 ||
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
218 (dims[0] == 0 && dims[1] == 0))));
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
219 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
221 public int getLength ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
222 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
223 return data.capacity ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
224 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
226 public double[] asDoubleVector ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
227 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
228 if (data instanceof DoubleBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
229 return toDouble ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
230 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
231 System.out.println ("Warning: invalid conversion to double vector");
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
232 return null;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
233 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
235 public double[][] asDoubleMatrix ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
236 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
237 if (cache != null)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
238 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
239 try { return (double[][])cache; }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
240 catch (ClassCastException e) { }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
241 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
243 if (data instanceof DoubleBuffer && dims.length == 2)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
244 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
245 double[][] m = new double[dims[0]][dims[1]];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
246 double[] data = ((DoubleBuffer)this.data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
247 int idx = 0;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
248 if (data.length > 0)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
249 for (int j = 0; j < m[0].length; j++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
250 for (int i = 0; i < m.length; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
251 m[i][j] = data[idx++];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
252 cache = m;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
253 return m;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
254 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
255 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
256 System.out.println ("Warning: invalid conversion to double matrix");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
258 return null;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
259 }
18013
501cb6a90f0f maint: Replace unnecessary tabs with spaces.
Rik <rik@octave.org>
parents: 17744
diff changeset
260
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
261 public double[][][] asDoubleMatrix3 ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
262 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
263 if (cache != null)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
264 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
265 try { return (double[][][])cache; }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
266 catch (ClassCastException e) { }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
267 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
269 if (data instanceof DoubleBuffer && dims.length == 3)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
270 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
271 double[][][] m = new double[dims[0]][dims[1]][dims[2]];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
272 double[] data = ((DoubleBuffer)this.data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
273 int idx = 0;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
274 if (data.length > 0)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
275 for (int k = 0; k < dims[2]; k++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
276 for (int j = 0; j < dims[1]; j++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
277 for (int i = 0; i < dims[0]; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
278 m[i][j][k] = data[idx++];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
279 cache = m;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
280 return m;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
281 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
282 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
283 System.out.println ("Warning: invalid conversion to double array");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
285 return null;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
286 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
288 public int[][] asIntMatrix ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
289 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
290 if (cache != null)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
291 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
292 try { return (int[][])cache; }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
293 catch (ClassCastException e) { }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
294 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
296 if (data instanceof IntBuffer && dims.length == 2)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
297 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
298 int[][] m = new int[dims[0]][dims[1]];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
299 int[] data = ((IntBuffer)this.data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
300 int idx = 0;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
301 if (data.length > 0)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
302 for (int j = 0; j < m[0].length; j++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
303 for (int i = 0; i < m.length; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
304 m[i][j] = data[idx++];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
305 cache = m;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
306 return m;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
307 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
308 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
309 System.out.println ("Warning: invalid conversion to integer matrix");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
311 return null;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
312 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
314 public double minValue ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
315 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
316 double val = Double.POSITIVE_INFINITY;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
318 if (data instanceof DoubleBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
319 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
320 double[] buf = ((DoubleBuffer)data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
321 for (int i = 0; i < buf.length; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
322 if (buf[i] < val)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
323 val = buf[i];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
324 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
325 else if (data instanceof ByteBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
326 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
327 byte[] buf = ((ByteBuffer)data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
328 for (int i = 0; i < buf.length; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
329 if (buf[i] < val)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
330 val = buf[i];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
331 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
332 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
333 System.out.println ("Warning: cannot compute min value for array of type `" + getClassName () + "'");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
335 return val;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
336 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
337
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
338 public double maxValue ()
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
339 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
340 double val = Double.NEGATIVE_INFINITY;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
342 if (data instanceof DoubleBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
343 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
344 double[] buf = ((DoubleBuffer)data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
345 for (int i = 0; i < buf.length; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
346 if (buf[i] > val)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
347 val = buf[i];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
348 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
349 else if (data instanceof ByteBuffer)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
350 {
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
351 byte[] buf = ((ByteBuffer)data).array ();
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
352 for (int i = 0; i <buf.length; i++)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
353 if (buf[i] > val)
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
354 val = buf[i];
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
355 }
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
356 else
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
357 System.out.println ("Warning: cannot compute max value for array of type `" + getClassName () + "'");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358
15753
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
359 return val;
6e39fe7992d9 style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents: 15625
diff changeset
360 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 }