Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move annotate(struct1, struct2) to IR #3201

Merged
merged 3 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/main/scala/is/hail/expr/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,24 @@ case class Apply(posn: Position, fn: String, args: Array[AST]) extends AST(posn,
} yield ir.ApplyBinaryPrimOp(op, x, y, t)
}

private[this] def tryIRConversion(agg: Option[String]): Option[IR] =
for {
irArgs <- anyFailAllFail(args.map(_.toIR(agg)))
ir <- tryPrimOpConversion(args.map(_.`type`).zip(irArgs)).orElse(
IRFunctionRegistry.lookupConversion(fn, args.map(_.`type`))
.map { irf => irf(irArgs) })
} yield ir

def toIR(agg: Option[String] = None): Option[IR] = {
fn match {
case "merge" | "select" | "drop" | "annotate" | "index" =>
case "merge" | "select" | "drop" | "index" =>
None
case "annotate" =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this special? is there something wrong with doing primo conversion on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AST for Apply("annotate", Seq(structA,structB)) doesn't place limitations on what structB is, since it just uses structA.typ.annotate(structB.typ). I don't want to handle the general case, so I'm only converting in the case that the annotate node looks like Apply("annotate", Seq(structA, StructConstructor(...))), which is I believe enough to handle all of our current uses in the Python.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will something like this work?

def maybeFindIRFunction(fn: String, args: Seq[AST]): Option[IR] = for {
  irArgs <- anyFailAllFail(args.map(_.toIR(agg)))
  ir <- tryPrimOpConversion(args.map(_.`type`).zip(irArgs)).orElse(
    IRFunctionRegistry.lookupFunction(fn, args.map(_.`type`))
      .map { irf => irf(irArgs) })
} yield ir

and

fn match {
  // ...
  case "annotate" =>
    if (!args(1).isInstanceOf[StructConstructor])
      None
    else
      maybeFindIRFunction(fn, args)
  case _ =>
    maybeFindIRFunction(fn, args)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I'll change.

if (!args(1).isInstanceOf[StructConstructor])
return None
tryIRConversion(agg)
case _ =>
for {
irArgs <- anyFailAllFail(args.map(_.toIR(agg)))
ir <- tryPrimOpConversion(args.map(_.`type`).zip(irArgs)).orElse(
IRFunctionRegistry.lookupConversion(fn, args.map(_.`type`))
.map { irf => irf(irArgs) })
} yield ir
tryIRConversion(agg)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/is/hail/expr/ir/functions/UtilFunctions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ object UtilFunctions extends RegistryFunctions {
registerIR("range", TInt32(), TInt32())(ArrayRange(_, _, I32(1)))

registerIR("range", TInt32())(ArrayRange(I32(0), _, I32(1)))

registerIR("annotate", tv("T", _.isInstanceOf[TStruct]), tv("U", _.isInstanceOf[TStruct])) { (s, annotations) =>
InsertFields(s, annotations.asInstanceOf[MakeStruct].fields)
}
}
}