OlgaOvcharenko commented on code in PR #1857:
URL: https://github.com/apache/systemds/pull/1857#discussion_r1259916685
##########
src/main/java/org/apache/sysds/runtime/frame/data/columns/RaggedArray.java:
##########
@@ -49,207 +49,261 @@ public class RaggedArray<T> extends Array<T> {
*/
public RaggedArray(T[] a, int m) {
super(m);
- throw new NotImplementedException();
+ this._a = ArrayFactory.create(a);
+ }
+
+ public RaggedArray(Array<T> a, int m) {
+ super(m);
+ this._a = a;
}
@Override
public void write(DataOutput out) throws IOException {
- throw new NotImplementedException("Unimplemented method
'write'");
+ _a.write(out);
}
@Override
public void readFields(DataInput in) throws IOException {
- throw new NotImplementedException("Unimplemented method
'readFields'");
+ _a.readFields(in);
}
@Override
public T get(int index) {
- throw new NotImplementedException("Unimplemented method 'get'");
+ if (index > super._size || index < 0)
+ throw new ArrayIndexOutOfBoundsException("Index " +
index + " out of bounds " + super._size);
+ return index < _a._size ? _a.get(index) : null;
+
+ }
+
+ protected Array<T> getInnerArray(){
+ return _a;
}
@Override
public Object get() {
- throw new NotImplementedException("Unimplemented method 'get'");
+ return _a.get();
}
@Override
public double getAsDouble(int i) {
- throw new NotImplementedException("Unimplemented method
'getAsDouble'");
+ return i < _a._size ? _a.getAsDouble(i) : Double.NaN;
+ }
+
+ @Override
+ public double getAsNaNDouble(int i) {
+ return i < _a._size ? _a.getAsNaNDouble(i) : Double.NaN;
}
@Override
public void set(int index, T value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if (index < _a._size)
+ _a.set(index, value);
}
@Override
public void set(int index, double value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if (index < _a._size)
+ _a.set(index, value);
}
@Override
public void set(int index, String value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if (index < _a._size)
+ _a.set(index, value);
}
@Override
public void setFromOtherType(int rl, int ru, Array<?> value) {
- throw new NotImplementedException("Unimplemented method
'setFromOtherType'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ _a.setFromOtherType(rl, ru, value);
}
@Override
public void set(int rl, int ru, Array<T> value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ if(value instanceof RaggedArray)
+ _a.set(rl, ru, ((RaggedArray)
value).getInnerArray());
+ else if(_a.getClass() == value.getClass())
+ _a.set(rl, ru, value);
+ else
+ throw new RuntimeException("RaggedArray set:
value type should be same to RaggedArray type " + _a.getClass());
}
+
@Override
public void set(int rl, int ru, Array<T> value, int rlSrc) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ if(value instanceof RaggedArray)
+ _a.set(rl, ru, ((RaggedArray)
value).getInnerArray(), rlSrc);
+ else if(_a.getClass() == value.getClass())
+ _a.set(rl, ru, value, rlSrc);
+ else
+ throw new RuntimeException("RaggedArray set:
value type should be same to RaggedArray type " + _a.getClass());
+
}
@Override
public void setNz(int rl, int ru, Array<T> value) {
- throw new NotImplementedException("Unimplemented method
'setNz'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ _a.setNz(rl, ru, value);
}
@Override
public void setFromOtherTypeNz(int rl, int ru, Array<?> value) {
- throw new NotImplementedException("Unimplemented method
'setFromOtherTypeNz'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ _a.setFromOtherTypeNz(rl, ru, value);
}
@Override
public void append(String value) {
- throw new NotImplementedException("Unimplemented method
'append'");
+ _a.append(value);
Review Comment:
But then in this case it is not a ragged array anymore. But sure if we
emulate normal behaviour.
##########
src/main/java/org/apache/sysds/runtime/frame/data/columns/RaggedArray.java:
##########
@@ -49,207 +49,261 @@ public class RaggedArray<T> extends Array<T> {
*/
public RaggedArray(T[] a, int m) {
super(m);
- throw new NotImplementedException();
+ this._a = ArrayFactory.create(a);
+ }
+
+ public RaggedArray(Array<T> a, int m) {
+ super(m);
+ this._a = a;
}
@Override
public void write(DataOutput out) throws IOException {
- throw new NotImplementedException("Unimplemented method
'write'");
+ _a.write(out);
}
@Override
public void readFields(DataInput in) throws IOException {
- throw new NotImplementedException("Unimplemented method
'readFields'");
+ _a.readFields(in);
}
@Override
public T get(int index) {
- throw new NotImplementedException("Unimplemented method 'get'");
+ if (index > super._size || index < 0)
+ throw new ArrayIndexOutOfBoundsException("Index " +
index + " out of bounds " + super._size);
+ return index < _a._size ? _a.get(index) : null;
+
+ }
+
+ protected Array<T> getInnerArray(){
+ return _a;
}
@Override
public Object get() {
- throw new NotImplementedException("Unimplemented method 'get'");
+ return _a.get();
}
@Override
public double getAsDouble(int i) {
- throw new NotImplementedException("Unimplemented method
'getAsDouble'");
+ return i < _a._size ? _a.getAsDouble(i) : Double.NaN;
+ }
+
+ @Override
+ public double getAsNaNDouble(int i) {
+ return i < _a._size ? _a.getAsNaNDouble(i) : Double.NaN;
}
@Override
public void set(int index, T value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if (index < _a._size)
+ _a.set(index, value);
}
@Override
public void set(int index, double value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if (index < _a._size)
+ _a.set(index, value);
}
@Override
public void set(int index, String value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if (index < _a._size)
+ _a.set(index, value);
}
@Override
public void setFromOtherType(int rl, int ru, Array<?> value) {
- throw new NotImplementedException("Unimplemented method
'setFromOtherType'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ _a.setFromOtherType(rl, ru, value);
}
@Override
public void set(int rl, int ru, Array<T> value) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ if(value instanceof RaggedArray)
+ _a.set(rl, ru, ((RaggedArray)
value).getInnerArray());
+ else if(_a.getClass() == value.getClass())
+ _a.set(rl, ru, value);
+ else
+ throw new RuntimeException("RaggedArray set:
value type should be same to RaggedArray type " + _a.getClass());
}
+
@Override
public void set(int rl, int ru, Array<T> value, int rlSrc) {
- throw new NotImplementedException("Unimplemented method 'set'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ if(value instanceof RaggedArray)
+ _a.set(rl, ru, ((RaggedArray)
value).getInnerArray(), rlSrc);
+ else if(_a.getClass() == value.getClass())
+ _a.set(rl, ru, value, rlSrc);
+ else
+ throw new RuntimeException("RaggedArray set:
value type should be same to RaggedArray type " + _a.getClass());
+
}
@Override
public void setNz(int rl, int ru, Array<T> value) {
- throw new NotImplementedException("Unimplemented method
'setNz'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ _a.setNz(rl, ru, value);
}
@Override
public void setFromOtherTypeNz(int rl, int ru, Array<?> value) {
- throw new NotImplementedException("Unimplemented method
'setFromOtherTypeNz'");
+ if(rl >= 0 && rl < _a._size && ru < _a._size)
+ _a.setFromOtherTypeNz(rl, ru, value);
}
@Override
public void append(String value) {
- throw new NotImplementedException("Unimplemented method
'append'");
+ _a.append(value);
Review Comment:
But then in this case it is not a ragged array anymore. But sure if we
emulate normal behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]