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