[jira] Created: (MATH-284) Avoid ArrayStoreException

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (MATH-284) Avoid ArrayStoreException

Gary D. Gregory (Jira)
Avoid ArrayStoreException
-------------------------

                 Key: MATH-284
                 URL: https://issues.apache.org/jira/browse/MATH-284
             Project: Commons Math
          Issue Type: Improvement
    Affects Versions: 2.0
            Reporter: Klaus Hartlage
            Priority: Minor


Add a new method
org.apache.commons.math,Field#getRuntimeClass():
...
    /**
     * Returns the runtime class of the FieldElement.
     *
     * @return The {@code Class} object that represents the runtime
     *         class of this object.
     */
    Class<? extends FieldElement> getRuntimeClass();
...

and replace all occurrences of
  Array.newInstance(field.getZero().getClass(),....)
with
  Array.newInstance(field.getRuntimeClass(),....)

to avoid the throwing of ArrayStoreException in the case you have a type hierachy of Fields with a common interface
and the array should have the interface type at runtime.





--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (MATH-284) Avoid ArrayStoreException

Gary D. Gregory (Jira)

     [ https://issues.apache.org/jira/browse/MATH-284?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe updated MATH-284:
-------------------------------

    Attachment: math-284.patch

The patch file above corresponds to your suggested change.
Could you check if this solves the problem in your case ?

I would like to wait a little before commiting it as it breaks compatibility (we add a method to a public interface). However, this interface is a new one and very few people are likely to implement it (in fact, I'm surprised someone used it so quickly). The compatibility break is easy to solve for users as they mainly have to create a one line method like:
{code}
public Class SomeTypeField implements Field<SomeType>, Serializable  {

    ...

    /** {@inheritDoc} */
    public Class<? extends FieldElement<SomeType>> getRuntimeClass() {
        return SomeType.class;
    }

}
{code}

Since the change you suggest is an interesting improvement and the compatibility break is easy to solve, I think it is worth adding it and breaking compatibility.

What do other people think ?

> Avoid ArrayStoreException
> -------------------------
>
>                 Key: MATH-284
>                 URL: https://issues.apache.org/jira/browse/MATH-284
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Klaus Hartlage
>            Priority: Minor
>         Attachments: math-284.patch
>
>
> Add a new method
> org.apache.commons.math,Field#getRuntimeClass():
> ...
>     /**
>      * Returns the runtime class of the FieldElement.
>      *
>      * @return The {@code Class} object that represents the runtime
>      *         class of this object.
>      */
>     Class<? extends FieldElement> getRuntimeClass();
> ...
> and replace all occurrences of
>   Array.newInstance(field.getZero().getClass(),....)
> with
>   Array.newInstance(field.getRuntimeClass(),....)
> to avoid the throwing of ArrayStoreException in the case you have a type hierachy of Fields with a common interface
> and the array should have the interface type at runtime.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (MATH-284) Avoid ArrayStoreException

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/MATH-284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12743900#action_12743900 ]

Klaus Hartlage commented on MATH-284:
-------------------------------------

Thanks.
Your patch works perfectly for me.

> Avoid ArrayStoreException
> -------------------------
>
>                 Key: MATH-284
>                 URL: https://issues.apache.org/jira/browse/MATH-284
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Klaus Hartlage
>            Priority: Minor
>         Attachments: math-284.patch
>
>
> Add a new method
> org.apache.commons.math,Field#getRuntimeClass():
> ...
>     /**
>      * Returns the runtime class of the FieldElement.
>      *
>      * @return The {@code Class} object that represents the runtime
>      *         class of this object.
>      */
>     Class<? extends FieldElement> getRuntimeClass();
> ...
> and replace all occurrences of
>   Array.newInstance(field.getZero().getClass(),....)
> with
>   Array.newInstance(field.getRuntimeClass(),....)
> to avoid the throwing of ArrayStoreException in the case you have a type hierachy of Fields with a common interface
> and the array should have the interface type at runtime.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (MATH-284) Avoid ArrayStoreException

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/MATH-284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12743932#action_12743932 ]

Phil Steitz commented on MATH-284:
----------------------------------

I am -1 on incompatible change until next major release.  Best to extend with a new interface including the new method.

> Avoid ArrayStoreException
> -------------------------
>
>                 Key: MATH-284
>                 URL: https://issues.apache.org/jira/browse/MATH-284
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Klaus Hartlage
>            Priority: Minor
>         Attachments: math-284.patch
>
>
> Add a new method
> org.apache.commons.math,Field#getRuntimeClass():
> ...
>     /**
>      * Returns the runtime class of the FieldElement.
>      *
>      * @return The {@code Class} object that represents the runtime
>      *         class of this object.
>      */
>     Class<? extends FieldElement> getRuntimeClass();
> ...
> and replace all occurrences of
>   Array.newInstance(field.getZero().getClass(),....)
> with
>   Array.newInstance(field.getRuntimeClass(),....)
> to avoid the throwing of ArrayStoreException in the case you have a type hierachy of Fields with a common interface
> and the array should have the interface type at runtime.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (MATH-284) Avoid ArrayStoreException

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/MATH-284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12794696#action_12794696 ]

Luc Maisonobe commented on MATH-284:
------------------------------------

Using a new interface would not help solving this issue as the linear algebra classes that use field elements are declared with respect to FieldElement wich in turns refer to Field and not some new ImprovedField interface.

Klaus, could you tell more about your use case so we can find another way to solve this ?
If I understand correctly, you have a hierarchy similar to:
{code}
public class Base implements FieldElement<Base> {

    public static final Base ZERO = new Base(...);

    public static final Base ONE    = new Base(...);

    BaseField getField() {
        return BaseField.getInstance();
    }

}

public class BaseField implements Field<Base> {

    public Base getZero() {
        return Base.ZERO;
    }

    public Base getOne() {
        return Base.ONE;
    }

}

public class Derived extends Base {
    ...
}
{code}

If this is the case could you tell us if your matrices can contain both Base and Derived elements. If so, then Derived should still rely on the base implementation of getField(), which would lead to Base[] arrays being allocated, as such arrays may contain Derived elements. If not, then Derived should implement its own getField() method and a DerivedField class should be created as well as Derived.ZERO and Derived.ONE to get a more specialized class.




> Avoid ArrayStoreException
> -------------------------
>
>                 Key: MATH-284
>                 URL: https://issues.apache.org/jira/browse/MATH-284
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Klaus Hartlage
>            Priority: Minor
>         Attachments: math-284.patch
>
>
> Add a new method
> org.apache.commons.math,Field#getRuntimeClass():
> ...
>     /**
>      * Returns the runtime class of the FieldElement.
>      *
>      * @return The {@code Class} object that represents the runtime
>      *         class of this object.
>      */
>     Class<? extends FieldElement> getRuntimeClass();
> ...
> and replace all occurrences of
>   Array.newInstance(field.getZero().getClass(),....)
> with
>   Array.newInstance(field.getRuntimeClass(),....)
> to avoid the throwing of ArrayStoreException in the case you have a type hierachy of Fields with a common interface
> and the array should have the interface type at runtime.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (MATH-284) Avoid ArrayStoreException

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/MATH-284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12804623#action_12804623 ]

Luc Maisonobe commented on MATH-284:
------------------------------------

This issue will have to wait at least for 3.0 as it introduces an incompatible change in a user interface.

> Avoid ArrayStoreException
> -------------------------
>
>                 Key: MATH-284
>                 URL: https://issues.apache.org/jira/browse/MATH-284
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Klaus Hartlage
>            Priority: Minor
>         Attachments: math-284.patch
>
>
> Add a new method
> org.apache.commons.math,Field#getRuntimeClass():
> ...
>     /**
>      * Returns the runtime class of the FieldElement.
>      *
>      * @return The {@code Class} object that represents the runtime
>      *         class of this object.
>      */
>     Class<? extends FieldElement> getRuntimeClass();
> ...
> and replace all occurrences of
>   Array.newInstance(field.getZero().getClass(),....)
> with
>   Array.newInstance(field.getRuntimeClass(),....)
> to avoid the throwing of ArrayStoreException in the case you have a type hierachy of Fields with a common interface
> and the array should have the interface type at runtime.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (MATH-284) Avoid ArrayStoreException

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

     [ https://issues.apache.org/jira/browse/MATH-284?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz updated MATH-284:
-----------------------------

    Fix Version/s: 3.0

> Avoid ArrayStoreException
> -------------------------
>
>                 Key: MATH-284
>                 URL: https://issues.apache.org/jira/browse/MATH-284
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Klaus Hartlage
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: math-284.patch
>
>
> Add a new method
> org.apache.commons.math,Field#getRuntimeClass():
> ...
>     /**
>      * Returns the runtime class of the FieldElement.
>      *
>      * @return The {@code Class} object that represents the runtime
>      *         class of this object.
>      */
>     Class<? extends FieldElement> getRuntimeClass();
> ...
> and replace all occurrences of
>   Array.newInstance(field.getZero().getClass(),....)
> with
>   Array.newInstance(field.getRuntimeClass(),....)
> to avoid the throwing of ArrayStoreException in the case you have a type hierachy of Fields with a common interface
> and the array should have the interface type at runtime.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.