2525import org .apache .sysds .runtime .controlprogram .context .ExecutionContext ;
2626import org .apache .sysds .runtime .functionobjects .DiagIndex ;
2727import org .apache .sysds .runtime .functionobjects .RevIndex ;
28+ import org .apache .sysds .runtime .functionobjects .RollIndex ;
2829import org .apache .sysds .runtime .functionobjects .SortIndex ;
2930import org .apache .sysds .runtime .functionobjects .SwapIndex ;
3031import org .apache .sysds .runtime .instructions .InstructionUtils ;
@@ -38,51 +39,58 @@ public class ReorgCPInstruction extends UnaryCPInstruction {
3839 private final CPOperand _col ;
3940 private final CPOperand _desc ;
4041 private final CPOperand _ixret ;
42+ private final CPOperand _shift ;
4143
4244 /**
4345 * for opcodes r' and rdiag
44- *
45- * @param op
46- * operator
47- * @param in
48- * cp input operand
49- * @param out
50- * cp output operand
51- * @param opcode
52- * the opcode
53- * @param istr
54- * ?
46+ *
47+ * @param op operator
48+ * @param in cp input operand
49+ * @param out cp output operand
50+ * @param opcode the opcode
51+ * @param istr ?
5552 */
5653 private ReorgCPInstruction (Operator op , CPOperand in , CPOperand out , String opcode , String istr ) {
5754 this (op , in , out , null , null , null , opcode , istr );
5855 }
5956
6057 /**
6158 * for opcode rsort
62- *
63- * @param op
64- * operator
65- * @param in
66- * cp input operand
67- * @param col
68- * ?
69- * @param desc
70- * ?
71- * @param ixret
72- * ?
73- * @param out
74- * cp output operand
75- * @param opcode
76- * the opcode
77- * @param istr
78- * ?
59+ *
60+ * @param op operator
61+ * @param in cp input operand
62+ * @param col ?
63+ * @param desc ?
64+ * @param ixret ?
65+ * @param out cp output operand
66+ * @param opcode the opcode
67+ * @param istr ?
7968 */
8069 private ReorgCPInstruction (Operator op , CPOperand in , CPOperand out , CPOperand col , CPOperand desc , CPOperand ixret ,
81- String opcode , String istr ) {
70+ String opcode , String istr ) {
8271 super (CPType .Reorg , op , in , out , opcode , istr );
8372 _col = col ;
8473 _desc = desc ;
8574 _ixret = ixret ;
75+ _shift = null ;
76+ }
77+
78+ /**
79+ * for opcode roll
80+ *
81+ * @param op operator
82+ * @param in cp input operand
83+ * @param shift ?
84+ * @param out cp output operand
85+ * @param opcode the opcode
86+ * @param istr ?
87+ */
88+ private ReorgCPInstruction (Operator op , CPOperand in , CPOperand out , CPOperand shift , String opcode , String istr ) {
89+ super (CPType .Reorg , op , in , out , opcode , istr );
90+ _col = null ;
91+ _desc = null ;
92+ _ixret = null ;
93+ _shift = shift ;
8694 }
8795
8896 public static ReorgCPInstruction parseInstruction ( String str ) {
@@ -103,6 +111,13 @@ else if ( opcode.equalsIgnoreCase("rev") ) {
103111 parseUnaryInstruction (str , in , out ); //max 2 operands
104112 return new ReorgCPInstruction (new ReorgOperator (RevIndex .getRevIndexFnObject ()), in , out , opcode , str );
105113 }
114+ else if (opcode .equalsIgnoreCase ("roll" )) {
115+ InstructionUtils .checkNumFields (str , 3 );
116+ in .split (parts [1 ]);
117+ out .split (parts [3 ]);
118+ CPOperand shift = new CPOperand (parts [2 ]);
119+ return new ReorgCPInstruction (new ReorgOperator (new RollIndex (0 )), in , out , shift , opcode , str );
120+ }
106121 else if ( opcode .equalsIgnoreCase ("rdiag" ) ) {
107122 parseUnaryInstruction (str , in , out ); //max 2 operands
108123 return new ReorgCPInstruction (new ReorgOperator (DiagIndex .getDiagIndexFnObject ()), in , out , opcode , str );
@@ -136,7 +151,12 @@ public void processInstruction(ExecutionContext ec) {
136151 boolean ixret = ec .getScalarInput (_ixret ).getBooleanValue ();
137152 r_op = r_op .setFn (new SortIndex (cols , desc , ixret ));
138153 }
139-
154+
155+ if (r_op .fn instanceof RollIndex ) {
156+ int shift = (int ) ec .getScalarInput (_shift ).getLongValue ();
157+ r_op = r_op .setFn (new RollIndex (shift ));
158+ }
159+
140160 //execute operation
141161 MatrixBlock soresBlock = matBlock .reorgOperations (r_op , new MatrixBlock (), 0 , 0 , 0 );
142162
0 commit comments