You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Arne Plöse (JIRA)" <ji...@apache.org> on 2011/05/09 16:18:03 UTC
[jira] [Created] (MATH-571) make FieldVector generic
make FieldVector generic
------------------------
Key: MATH-571
URL: https://issues.apache.org/jira/browse/MATH-571
Project: Commons Math
Issue Type: Improvement
Affects Versions: 3.0
Reporter: Arne Plöse
Priority: Minor
make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
solution see attached code
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Closed] (MATH-571) make FieldVector generic
Posted by "Luc Maisonobe (Closed) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Luc Maisonobe closed MATH-571.
------------------------------
changing status to closed as 3.0 has been released
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Reporter: Arne Plöse
> Priority: Minor
> Fix For: 3.0
>
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-571) make FieldVector generic
Posted by "Arne Plöse (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13031360#comment-13031360 ]
Arne Plöse commented on MATH-571:
---------------------------------
Maybe this code works ... Yes it looks ugly ...
I want to extend FieldElement and wnt it use in vector and matrix.
so the problem is getting the right "backing class" for the interface.
For the matrix is a third generics needed....
Maybe someone has a better solution here is my "draft".
public class App
{
public static interface FieldElement<T> {
T add(T a);
}
public static interface FieldVector<T extends FieldElement<T>, V extends FieldVector> {
V multiply(FieldVector<T, ?> v);
V createVector(T[] data);
}
public static interface ComplexFieldElement<T extends ComplexFieldElement<T>> extends FieldElement<T> {
double getReal();
T conjugate();
}
public static class Complex implements ComplexFieldElement<Complex> {
@Override
public double getReal() {
return 1;
}
@Override
public Complex add(Complex a) {
return new Complex();
}
@Override
public Complex conjugate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static interface GenericComplexFieldVector<T extends ComplexFieldElement<T>, V extends GenericComplexFieldVector> extends FieldVector<T, V> {
V conjugate();
double[] getReal();
}
public abstract static class AbstractArrayFieldVector<T extends FieldElement<T>, V extends FieldVector> implements FieldVector<T, V> {
protected T[] data;
@Override
public V multiply(FieldVector<T, ?> v) {
return createVector(data);
}
}
public static class ArrayFieldVector<T extends FieldElement<T>> extends AbstractArrayFieldVector<T, FieldVector> {
@Override
public ArrayFieldVector createVector(T[] data) {
ArrayFieldVector result = new ArrayFieldVector();
result.data = data;
return result;
}
}
public abstract static class AbstractArrayComplexVector<T extends ComplexFieldElement<T>, V extends GenericComplexFieldVector> extends AbstractArrayFieldVector<T, V> implements GenericComplexFieldVector<T, V>{
@Override
public double[] getReal() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public V conjugate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static interface ComplexVector extends GenericComplexFieldVector<Complex, ComplexVector> {
}
public static class ArrayComplexVector extends AbstractArrayComplexVector<Complex, ComplexVector> implements ComplexVector {
@Override
public ComplexVector createVector(Complex[] data) {
ArrayComplexVector result = new ArrayComplexVector();
result.data = data;
return (ComplexVector)result;
}
}
public static void main(String [] args) {
ArrayComplexVector v = new ArrayComplexVector();
ComplexVector v1 = v.multiply(new ArrayComplexVector()); // FiledVector type survives ...
FieldVector<Complex, ?> v2 = v1.multiply(v);
FieldVector<Complex, FieldVector> v3 = v2.multiply(v2);
}
}
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Arne Plöse
> Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-571) make FieldVector generic
Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13030839#comment-13030839 ]
Luc Maisonobe commented on MATH-571:
------------------------------------
I am not sure to understand what you mean. Do you want to add the second R parameter for the sake of implementing a copy method ?
The current way of copying a vector would be to use
{code}
ArrayComplexVector v = new ArrayComplexVector();
ArrayComplexVector v1 = new ArrayComplexVector(v);
{code}
Can you explain further what you need ?
Thanks
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Arne Plöse
> Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-571) make FieldVector generic
Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13031300#comment-13031300 ]
Luc Maisonobe commented on MATH-571:
------------------------------------
I am slowly starting to understand.
Do you think ArrayFieldVectorExtendable interface is really needed or should the createVector method by directly implemented in ArrayFieldVector ?
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Arne Plöse
> Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-571) make FieldVector generic
Posted by "Arne Plöse (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13031066#comment-13031066 ]
Arne Plöse commented on MATH-571:
---------------------------------
copy was just an example ... this change goes for all methods that generates an Fieldvector as output i.e. ebeMultiply ...
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Arne Plöse
> Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (MATH-571) make FieldVector generic
Posted by "Arne Plöse (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Arne Plöse updated MATH-571:
----------------------------
Description:
make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
solution:
public class InheritationTest {
public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
R copy();
}
public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
protected T[] data;
@Override
public R copy() {
return createVector(data);
}
abstract protected R createVector(T[] data);
}
public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
@Override
protected ArrayFieldVector<T> createVector(T[] data) {
ArrayFieldVector<T> result = new ArrayFieldVector<T>();
result.data = data;
return result;
}
}
public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
@Override
protected ArrayComplexVector createVector(Complex[] data) {
ArrayComplexVector result = new ArrayComplexVector();
result.data = data;
return result;
}
public double[] getReal() {
return null;
}
public double[] getImaginary() {
return null;
}
}
public void test() {
ArrayComplexVector v = new ArrayComplexVector();
ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
}
}
was:
make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
solution see attached code
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Arne Plöse
> Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-571) make FieldVector generic
Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13031632#comment-13031632 ]
Luc Maisonobe commented on MATH-571:
------------------------------------
Lets take some time to review this, don't jump on the keyboard immediately.
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Arne Plöse
> Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-571) make FieldVector generic
Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13082504#comment-13082504 ]
Luc Maisonobe commented on MATH-571:
------------------------------------
OK for WONT_FIX for both this issue and MATH-569
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Reporter: Arne Plöse
> Priority: Minor
> Fix For: 3.0
>
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (MATH-571) make FieldVector generic
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz updated MATH-571:
-----------------------------
Affects Version/s: (was: 3.0)
Fix Version/s: 3.0
My inclination is WONT_FIX here; but if we do decide to go this route, we need to do it in 3.0
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Reporter: Arne Plöse
> Priority: Minor
> Fix For: 3.0
>
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (MATH-571) make FieldVector generic
Posted by "Luc Maisonobe (Resolved) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Luc Maisonobe resolved MATH-571.
--------------------------------
Resolution: Won't Fix
Setting to Won't Fix as per comments above.
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Reporter: Arne Plöse
> Priority: Minor
> Fix For: 3.0
>
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-571) make FieldVector generic
Posted by "Arne Plöse (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13031627#comment-13031627 ]
Arne Plöse commented on MATH-571:
---------------------------------
Here is my latest, if it looks promising, I will give it a try to make the big step and change the sources, test ...
If you thing this is not the way things should go, let me know before I waste my time on it.
/*
* To each fieldElement interface belangs a fieldvector and fieldMatrix interface.
* if I create a new fieldElement I need a new fieldvector and fieldMatrix.
* The Abstract* classes implement these iterfaces and are open
* the classes without the Abstract prefix are final and hide the vector and maticx interfaces...
* so each new fieldElement results in 3 new interfaces and 4 new classes :-)
*/
public class App
{
public static interface FieldElement<T> {
T add(T a);
//not really needed, but just to male sure one can mutiply a sclar to a vector ... vector times scalar is implemented in vector
<V extends FieldVector> V mapMultiply(V v);
}
public static interface FieldVector<T extends FieldElement<T>, M extends FieldMatrix, V extends FieldVector> {
V ebeMultiply(FieldVector<T, M, V> v);
V mapMultiply(T v);
M multiply(FieldVector<T, M, V> v);
V createVector(T[] data);
V createVector(FieldVector<T, ?, ?> v);
M createMatrix(T[][] data);
M createMatrix(FieldMatrix<T, ?, ?> v);
T procuct();
}
public static interface FieldMatrix<T extends FieldElement<T>, M extends FieldMatrix, V extends FieldVector> {
M multiply(FieldVector<T, M, V> v);
M createMatrix(T[][] data);
M createMatrix(FieldMatrix<T, ?, ?> v);
V createVector(T[] data);
V createVector(FieldVector<T, ?, ?> v);
V getRow(int i);
}
// generic interface that one can implement a BigReal ... CoplexClass if needed
public static interface ComplexFieldElement<T extends ComplexFieldElement<T>> extends FieldElement<T> {
T conjugate();
}
public static interface GenericComplexFieldVector<T extends ComplexFieldElement<T>, M extends GenericComplexFieldMatrix, V extends GenericComplexFieldVector> extends FieldVector<T, M, V> {
V conjugate();
}
public static interface GenericComplexFieldMatrix<T extends ComplexFieldElement<T>, M extends GenericComplexFieldMatrix, V extends GenericComplexFieldVector> extends FieldMatrix<T, M, V> {
M conjugate();
}
public abstract static class AbstractArrayFieldVector<T extends FieldElement<T>, M extends FieldMatrix, V extends FieldVector> implements FieldVector<T, M, V> {
protected T[] data;
@Override
public V ebeMultiply(FieldVector<T, M, V> v) {
return createVector(data);
}
@Override
public V mapMultiply(T v) {
return createVector(data);
}
@Override
public M multiply(FieldVector<T, M, V> v) {
return createMatrix((T[][])null);
}
@Override
public T procuct() {
return null;
}
}
public abstract static class AbstractArrayFieldMatrix<T extends FieldElement<T>, M extends FieldMatrix, V extends FieldVector> implements FieldMatrix<T, M, V> {
protected T[][] data;
@Override
public M multiply(FieldVector<T, M, V> v) {
return createMatrix(data);
}
@Override
public V getRow(int i) {
return createVector((T[])null);
}
}
// get rid of the vector and matrix
public final static class ArrayFieldVector<T extends FieldElement<T>> extends AbstractArrayFieldVector<T, FieldMatrix, FieldVector> {
@Override
public ArrayFieldVector createVector(T[] data) {
ArrayFieldVector result = new ArrayFieldVector();
result.data = data;
return result;
}
@Override
public FieldMatrix createMatrix(T[][] data) {
ArrayFieldMatrix result = new ArrayFieldMatrix();
result.data = data;
return result;
}
@Override
public FieldVector createVector(FieldVector<T, ?, ?> v) {
ArrayFieldVector result = new ArrayFieldVector();
return result;
}
@Override
public FieldMatrix createMatrix(FieldMatrix<T, ?, ?> v) {
ArrayFieldMatrix result = new ArrayFieldMatrix();
return result;
}
}
// get rid of the vector and matrix
public final static class ArrayFieldMatrix<T extends FieldElement<T>> extends AbstractArrayFieldMatrix<T, FieldMatrix, FieldVector> {
@Override
public FieldVector createVector(T[] data) {
ArrayFieldVector result = new ArrayFieldVector();
result.data = data;
return result;
}
@Override
public FieldMatrix createMatrix(T[][] data) {
ArrayFieldMatrix result = new ArrayFieldMatrix();
result.data = data;
return result;
}
@Override
public FieldMatrix createMatrix(FieldMatrix<T, ?, ?> v) {
ArrayFieldMatrix result = new ArrayFieldMatrix();
return result;
}
@Override
public FieldVector createVector(FieldVector<T, ?, ?> v) {
ArrayFieldVector result = new ArrayFieldVector();
return result;
}
}
public abstract static class AbstractArrayComplexVector<T extends ComplexFieldElement<T>, M extends GenericComplexFieldMatrix, V extends GenericComplexFieldVector> extends AbstractArrayFieldVector<T, M, V> implements GenericComplexFieldVector<T, M, V>{
@Override
public V conjugate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public abstract static class AbstractArrayComplexMatrix<T extends ComplexFieldElement<T>, M extends GenericComplexFieldMatrix, V extends GenericComplexFieldVector> extends AbstractArrayFieldMatrix<T, M, V> implements GenericComplexFieldMatrix<T, M, V> {
@Override
public M conjugate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
// should better be named ComplexDouble ...
public static class Complex implements ComplexFieldElement<Complex> {
public double getReal() {
return 1;
}
@Override
public Complex add(Complex a) {
return new Complex();
}
@Override
public Complex conjugate() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <V extends FieldVector> V mapMultiply(V v) {
return (V)v.mapMultiply(this); // Call vectors mapMultiply
}
}
// should better be named ComplexDoubleVector ...
public static interface ComplexVector extends GenericComplexFieldVector<Complex, ComplexMatrix, ComplexVector> {
double[] getReal();
}
// should better be named ComplexDoubleMatrix ...
public static interface ComplexMatrix extends GenericComplexFieldMatrix<Complex, ComplexMatrix, ComplexVector> {
double[][] getReal();
}
// get rid of the fieldElement, vector and matrix
public final static class ArrayComplexVector extends AbstractArrayComplexVector<Complex, ComplexMatrix, ComplexVector> implements ComplexVector {
@Override
public ComplexVector createVector(Complex[] data) {
ArrayComplexVector result = new ArrayComplexVector();
result.data = data;
return result;
}
@Override
public ComplexMatrix createMatrix(Complex[][] data) {
ArrayComplexMatrix result = new ArrayComplexMatrix();
return result;
}
@Override
public double[] getReal() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ComplexVector createVector(FieldVector<Complex, ?, ?> v) {
ArrayComplexVector result = new ArrayComplexVector();
return result;
}
@Override
public ComplexMatrix createMatrix(FieldMatrix<Complex, ?, ?> v) {
ArrayComplexMatrix result = new ArrayComplexMatrix();
return result;
}
}
// get rid of the fieldElement, vector and matrix ... its just a matric of Copmplex
public final static class ArrayComplexMatrix extends AbstractArrayComplexMatrix<Complex, ComplexMatrix, ComplexVector> implements ComplexMatrix {
@Override
public ComplexVector createVector(Complex[] data) {
ArrayComplexVector result = new ArrayComplexVector();
result.data = data;
return result;
}
@Override
public ComplexMatrix createMatrix(Complex[][] data) {
ArrayComplexMatrix result = new ArrayComplexMatrix();
return result;
}
@Override
public double[][] getReal() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ComplexMatrix createMatrix(FieldMatrix<Complex, ?, ?> v) {
ArrayComplexMatrix result = new ArrayComplexMatrix();
return result;
}
@Override
public ComplexVector createVector(FieldVector<Complex, ?, ?> v) {
ArrayComplexVector result = new ArrayComplexVector();
return result;
}
}
public static class SomeFancyStuff<T extends FieldElement<T>, M extends FieldMatrix, V extends FieldVector> {
private V v;
private M m;
public SomeFancyStuff(M m) {
this.m = m;
v = (V)m.getRow(0);
}
V getV() {
return v;
}
}
public static class SomeFancyStuffComplex<T extends ComplexFieldElement<T>, M extends ComplexMatrix, V extends ComplexVector> {
private V v;
private M m;
public SomeFancyStuffComplex(M m) {
this.m = m;
v = (V)m.getRow(0);
}
V getV() {
return v;
}
}
public static void main(String [] args) {
ComplexVector v = new ArrayComplexVector();
ComplexMatrix m1 = v.multiply(new ArrayComplexVector()); // FiledVector type survives ...
FieldVector<Complex, ?, ?> v2 = m1.getRow(0);
ComplexVector v3 = m1.getRow(1);
SomeFancyStuff<Complex, FieldMatrix, FieldVector> sf1 = new SomeFancyStuff<Complex, FieldMatrix, FieldVector>(new ArrayFieldMatrix<Complex>());
SomeFancyStuffComplex sf2 = new SomeFancyStuffComplex(new ArrayComplexMatrix());
SomeFancyStuff<Complex, FieldMatrix, FieldVector> sf3 = new SomeFancyStuff<Complex, FieldMatrix, FieldVector>(new ArrayComplexMatrix());
v2= sf1.getV();
v3 = sf2.getV();
v2 = sf3.getV();
Complex c = new Complex();
ComplexVector v4 = c.mapMultiply(v);
FieldVector<Complex, FieldMatrix, FieldVector> vc = c.mapMultiply(new ArrayFieldVector<Complex>());
Complex c1 = vc.procuct();
}
}
> make FieldVector generic
> ------------------------
>
> Key: MATH-571
> URL: https://issues.apache.org/jira/browse/MATH-571
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Arne Plöse
> Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
> public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector> {
> R copy();
> }
> public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>, R extends FieldVector> implements FieldVector<T, R>, Serializable {
> protected T[] data;
> @Override
> public R copy() {
> return createVector(data);
> }
> abstract protected R createVector(T[] data);
> }
> public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T, ArrayFieldVector> {
> @Override
> protected ArrayFieldVector<T> createVector(T[] data) {
> ArrayFieldVector<T> result = new ArrayFieldVector<T>();
> result.data = data;
> return result;
> }
> }
> public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex, ArrayComplexVector> {
> @Override
> protected ArrayComplexVector createVector(Complex[] data) {
> ArrayComplexVector result = new ArrayComplexVector();
> result.data = data;
> return result;
> }
> public double[] getReal() {
> return null;
> }
> public double[] getImaginary() {
> return null;
> }
> }
> public void test() {
> ArrayComplexVector v = new ArrayComplexVector();
> ArrayComplexVector v1 = v.copy(); // FiledVector type survives ...
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira