You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2018/05/23 05:37:50 UTC
systemml git commit: [MINOR] Fix incorrect list indexing range check,
extended name handling
Repository: systemml
Updated Branches:
refs/heads/master b85aea348 -> 96954b4ca
[MINOR] Fix incorrect list indexing range check, extended name handling
Closes #766.
Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/96954b4c
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/96954b4c
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/96954b4c
Branch: refs/heads/master
Commit: 96954b4ca980d928bf2c4c4eb012efe0188a4ac6
Parents: b85aea3
Author: EdgarLGB <gu...@atos.net>
Authored: Tue May 22 22:23:59 2018 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Tue May 22 22:35:07 2018 -0700
----------------------------------------------------------------------
.../runtime/instructions/cp/ListObject.java | 57 +++++++++++---------
1 file changed, 31 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/systemml/blob/96954b4c/src/main/java/org/apache/sysml/runtime/instructions/cp/ListObject.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/ListObject.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/ListObject.java
index 0fdb1e8..95f03b5 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/cp/ListObject.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/ListObject.java
@@ -26,8 +26,7 @@ import org.apache.sysml.parser.Expression.DataType;
import org.apache.sysml.parser.Expression.ValueType;
import org.apache.sysml.runtime.DMLRuntimeException;
-public class ListObject extends Data
-{
+public class ListObject extends Data {
private static final long serialVersionUID = 3652422061598967358L;
private final List<String> _names;
@@ -63,57 +62,63 @@ public class ListObject extends Data
}
public ListObject slice(int ix1, int ix2) {
- ListObject ret = new ListObject(_data.subList(ix1, ix2+1),
- (_names!=null) ? _names.subList(ix1, ix2+1) : null);
- ret.setStatus(Arrays.copyOfRange(_dataState, ix2, ix2+1));
+ ListObject ret = new ListObject(_data.subList(ix1, ix2 + 1),
+ (_names != null) ? _names.subList(ix1, ix2 + 1) : null);
+ ret.setStatus(Arrays.copyOfRange(_dataState, ix2, ix2 + 1));
return ret;
}
public Data slice(String name) {
//check for existing named list
- if( _names == null )
- throw new DMLRuntimeException("Invalid lookup by name"
- + " in unnamed list: "+name+".");
-
+ if (_names == null)
+ throw new DMLRuntimeException("Invalid lookup by name" + " in unnamed list: " + name + ".");
+
//find position and check for existing entry
int pos = _names.indexOf(name);
- if( pos <= 0 || pos >= _data.size() )
- throw new DMLRuntimeException("List lookup returned no entry for name='"+name+"'");
-
+ if (pos < 0 || pos >= _data.size())
+ throw new DMLRuntimeException("List lookup returned no entry for name='" + name + "'");
+
//return existing entry
return slice(pos);
}
public ListObject slice(String name1, String name2) {
//check for existing named list
- if( _names == null )
- throw new DMLRuntimeException("Invalid lookup by name"
- + " in unnamed list: "+name1+", "+name2+".");
-
+ if (_names == null)
+ throw new DMLRuntimeException("Invalid lookup by name" + " in unnamed list: " + name1 + ", " + name2 + ".");
+
//find position and check for existing entry
int pos1 = _names.indexOf(name1);
int pos2 = _names.indexOf(name2);
- if( pos1 <= 0 || pos1 >= _data.size() )
- throw new DMLRuntimeException("List lookup returned no entry for name='"+name1+"'");
- if( pos2 <= 0 || pos2 >= _data.size() )
- throw new DMLRuntimeException("List lookup returned no entry for name='"+name2+"'");
-
+ if (pos1 < 0 || pos1 >= _data.size())
+ throw new DMLRuntimeException("List lookup returned no entry for name='" + name1 + "'");
+ if (pos2 < 0 || pos2 >= _data.size())
+ throw new DMLRuntimeException("List lookup returned no entry for name='" + name2 + "'");
+
//return list object
return slice(pos1, pos2);
}
-
+
+ public List<String> getNames() {
+ return _names;
+ }
+
+ public String getName(int ix) {
+ return (_names == null) ? null : _names.get(ix);
+ }
+
@Override
public String getDebugName() {
return toString();
}
@Override
- public String toString() {
+ public String toString() {
StringBuilder sb = new StringBuilder("List (");
- for( int i=0; i<_data.size(); i++ ) {
- if( i > 0 )
+ for (int i = 0; i < _data.size(); i++) {
+ if (i > 0)
sb.append(", ");
- if( _names != null ) {
+ if (_names != null) {
sb.append(_names.get(i));
sb.append("=");
}