Menu

#12 Matrix Support

pending
Fathzer
FeatureRequest
None
2015-10-06
2015-10-04
Anonymous
No

In current model of library matrix support can be addedd easily like every matrix can be treated as operand or argument in case of function. Operations on matrix can be performed using third party libraries such as JAMA and EJML etc.

Discussion

  • Fathzer

    Fathzer - 2015-10-06

    Here is a copy of a discussion I had with the author of the initial post:
    I want to use string representation for matrix For example this expression given by user "2+3*6*[[1,2,3],[4,5,6]]-9" in current implementation "+", " -", "/", "%", "(", ")" and "," are used as token delimiter. When first time toValue() is called it will pass "2" then "3" and then "6" after that it will give "[[1" because comma(,) is delimiter so it tokenize but It should pass the complete matrix "[[1,2,3],[4,5,6]]". When matrix is in this format "[[1 2 3][4 5 6]]" complete matrix is passed by toValue() function because this syntax of matrix does not contain any delimiter. But I can't use this syntax because my matrix may contain complex number like "2+3i" and may contain expression at any index. So what I want is that when toValue() function is called it should pass complete matrix instead of delimited matrix at delimiter within matrix. I am trying to add this functionality by my own but having hard time in understanding the flow of library. I would be very grateful if you add this functionality to library or tell me the flow of library. Thanks in advance for help.

     

    Last edit: Fathzer 2015-10-06
  • Fathzer

    Fathzer - 2015-10-06

    Hi,
    My understanding is the problem you have is '+' is not a token delimiter when it is included in brackets.
    The default tokenize mechanism is not able to deal with that case. Hopefully, you can override the AbstractEvaluator.tokenize(String) method. Here is a quick and dirty implementation. Maybe you should improve it using regular expressions.

        @Override
        protected Iterator<String> tokenize(String expression) {
            String delimiters = "+-*/%";
            ArrayList<String> tokens = new ArrayList<String>();
            StringBuilder current = new StringBuilder();
            int bracketDepth = 0;
            for (int i = 0; i < expression.length(); i++) {
                if (expression.charAt(i)=='[') {
                    bracketDepth++;
                    current.append(expression.charAt(i));
                } else if (expression.charAt(i)==']' && bracketDepth>0) {
                    bracketDepth--;
                    current.append(expression.charAt(i));
                } else if (delimiters.indexOf(expression.charAt(i))>=0 && bracketDepth==0) {
                    tokens.add(current.toString());
                    tokens.add(expression.substring(i, i+1));
                    current.delete(0, current.length());
                } else {
                    current.append(expression.charAt(i));
                }
            }
            if (current.length()>0) {
                tokens.add(current.toString());
            }
            return tokens.iterator();
        }
    

    Best regards
    Jean-Marc Astesana

     

    Last edit: Fathzer 2015-10-06
  • Anonymous

    Anonymous - 2015-10-06

    Thank you very much :-)

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.