{"action":"created","comment":{"url":"https://api.github.com/repos/scalanlp/breeze/pulls/comments/62540125","id":62540125,"diff_hunk":"@@ -18,7 +18,79 @@ import spire.syntax.cfor._\n import scala.{specialized=>spec}\n import scala.reflect.ClassTag\n import scalaxy.debug._\n+import breeze.generic.UFunc\n+import breeze.linalg.eig.Eig\n+\n+/*@author acampbell */\n+trait DenseMatrixPowerStuff extends DenseMatrixOps\n+\t\t\t       with DenseMatrixPowerOps\n+\t\t\t       with LowPriorityDenseMatrix { this: DenseMatrix.type =>\n+  // <editor-fold defaultstate=\"collapsed\" desc=\" OpPow implementations \">\n+\n+  def expBySq(exp: Double, mat: DenseMatrix[Double]): DenseMatrix[Double] = {\n+    if (exp == 1) mat\n+    else if (exp % 2 == 1) mat * expBySq(exp - 1, mat)\n+    else {\n+      val h = expBySq(exp / 2, mat)\n+      h * h\n+    }\n+  }\n+\n+implicit object implOpPow_DMD_Deq_DMD\n+extends OpPow.Impl2[DenseMatrix[Double], Double, DenseMatrix[Double]] {\n+  def apply(_a: DenseMatrix[Double], _b: Double): DenseMatrix[Double] = {\n+    requireSquareMatrix(_a)\n+    val Eig(real, imag, evectors) = eig(_a)\n+    norm(imag, 1.0) match {\n+      case 0.0 =>\n+\tval exped = new DenseVector(real.data.map(scala.math.pow(_, _b)))\n+\tval r = (implOpSolveMatrixBy_DMD_DMD_eq_DMD(evectors.t, (evectors * diag(exped)).t)).t\n+\tr\n+      case _ => expBySq(_b, _a)\n+    }\n+  }\n+  implicitly[BinaryRegistry[Matrix[Double], Double, OpPow.type, Matrix[Double]]].register(this)\n+  implicitly[BinaryRegistry[DenseMatrix[Double], Double, OpPow.type, DenseMatrix[Double]]].register(this)\n+}\n+\n \n+implicit object implOpPow_DMD_Ieq_DMD\n+extends OpPow.Impl2[DenseMatrix[Double], Int, DenseMatrix[Double]] {\n+  def apply(_a: DenseMatrix[Double], _b: Int): DenseMatrix[Double] = {\n+    implOpPow_DMD_Deq_DMD(_a,_b)\n+  }\n+}\n+\n+implicit object implOpPow_IMI_Ieq_IMI\n+extends OpPow.Impl2[DenseMatrix[Int], Int, DenseMatrix[Int]] {\n+  def apply(_a: DenseMatrix[Int], _b: Int): DenseMatrix[Int] = {\n+    val t = DenseMatrix((0, 0, 0), (0, 0, 0), (0, 0, 0))\n+    t","path":"math/src/main/scala/breeze/linalg/operators/DenseMatrixOps.scala","position":51,"original_position":51,"commit_id":"3a7b1c23247e655df8268b01b54fbdd835c21d6a","original_commit_id":"3a7b1c23247e655df8268b01b54fbdd835c21d6a","user":{"login":"claydonkey","id":5519575,"avatar_url":"https://avatars.githubusercontent.com/u/5519575?v=3","gravatar_id":"","url":"https://api.github.com/users/claydonkey","html_url":"https://github.com/claydonkey","followers_url":"https://api.github.com/users/claydonkey/followers","following_url":"https://api.github.com/users/claydonkey/following{/other_user}","gists_url":"https://api.github.com/users/claydonkey/gists{/gist_id}","starred_url":"https://api.github.com/users/claydonkey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claydonkey/subscriptions","organizations_url":"https://api.github.com/users/claydonkey/orgs","repos_url":"https://api.github.com/users/claydonkey/repos","events_url":"https://api.github.com/users/claydonkey/events{/privacy}","received_events_url":"https://api.github.com/users/claydonkey/received_events","type":"User","site_admin":false},"body":"Sorry about this. This is just me experimenting\r\n\r\n- Is **implOpPow_DMD_Ieq_DMD** ok (as an overload)?\r\n- Is there any point in creating  **implOpPow_IMI_Ieq_IMI** - an integer only function? \r\n 1. \r\nIs it even possible ?\r\n 2. \r\n Does it ditch the need for floating point, which would be the only reason for it - I suppose\r\n\r\nI was trying to understand why [T:Numeric] can't be used as a generic type to create a one size fits all function instead of why each function has to have its generic argument types declared explicitly and ultimate behaves more like classic OO overloading.\r\n\r\nOn closer inspection I understand that trying to create a function like: \r\n```scala\r\n  implicit def implOpPow_DMT_B_eq_DMT[T,B](implicit op: OpPow.Impl2[DenseMatrix[T], B, DenseMatrix[T]]):\r\n  OpPow.Impl2[DenseMatrix[T], B,  DenseMatrix[T]] =\r\n   new OpPow.Impl2[DenseMatrix[T], B, DenseMatrix[T]] {\r\n      override def apply(_a: DenseMatrix[T], _b: B): DenseMatrix[T] = {\r\n\trequireSquareMatrix(_a)\r\n\tval Eig(real, imag, evectors) = eig(_a)\r\n\t...\r\n\t}\r\n      }\r\n```\r\nis a futile because the singleton eig requires a DenseVector[Double]","created_at":"2016-05-09T17:40:47Z","updated_at":"2016-05-09T17:40:47Z","html_url":"https://github.com/scalanlp/breeze/pull/531#discussion_r62540125","pull_request_url":"https://api.github.com/repos/scalanlp/breeze/pulls/531","_links":{"self":{"href":"https://api.github.com/repos/scalanlp/breeze/pulls/comments/62540125"},"html":{"href":"https://github.com/scalanlp/breeze/pull/531#discussion_r62540125"},"pull_request":{"href":"https://api.github.com/repos/scalanlp/breeze/pulls/531"}}},"pull_request":{"url":"https://api.github.com/repos/scalanlp/breeze/pulls/531","id":69253072,"html_url":"https://github.com/scalanlp/breeze/pull/531","diff_url":"https://github.com/scalanlp/breeze/pull/531.diff","patch_url":"https://github.com/scalanlp/breeze/pull/531.patch","issue_url":"https://api.github.com/repos/scalanlp/breeze/issues/531","number":531,"state":"open","locked":false,"title":"Backtobreeze","user":{"login":"claydonkey","id":5519575,"avatar_url":"https://avatars.githubusercontent.com/u/5519575?v=3","gravatar_id":"","url":"https://api.github.com/users/claydonkey","html_url":"https://github.com/claydonkey","followers_url":"https://api.github.com/users/claydonkey/followers","following_url":"https://api.github.com/users/claydonkey/following{/other_user}","gists_url":"https://api.github.com/users/claydonkey/gists{/gist_id}","starred_url":"https://api.github.com/users/claydonkey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claydonkey/subscriptions","organizations_url":"https://api.github.com/users/claydonkey/orgs","repos_url":"https://api.github.com/users/claydonkey/repos","events_url":"https://api.github.com/users/claydonkey/events{/privacy}","received_events_url":"https://api.github.com/users/claydonkey/received_events","type":"User","site_admin":false},"body":"I was a bit surprised that there was no implementation in breeze to take the power of a matrix.\r\nCurrently there is the mpow function in breeze.linalg.functions but it fails to deliver for both Matrices with Complex Eigen values and/or Defective Matrices\r\nI put in the rudimentary exponentiation by squaring here and also took the liberty of using the caret symbol for exp and began working on adding to the DenseMatrixOps\r\n\r\nI suppose the best way to explain is with an example (better example in attachment):\r\n```scala\r\nscala> val M = diag(DenseVector(1.0,2.0,3.0,4.0))\r\nM: breeze.linalg.DenseMatrix[Double] =\r\n1.0  0.0  0.0  0.0\r\n0.0  2.0  0.0  0.0\r\n0.0  0.0  3.0  0.0\r\n0.0  0.0  0.0  4.0\r\n`\r\nscala> M ^ 2\r\nres0: breeze.linalg.DenseMatrix[Double] =\r\n1.0  0.0  0.0  0.0\r\n0.0  4.0  0.0  0.0\r\n0.0  0.0  9.0  0.0\r\n0.0  0.0  0.0  16.0\r\n\r\nscala> M(4,::) := DenseVector(1.0,2.0,3.0,4.0).t\r\nres12: breeze.linalg.Transpose[breeze.linalg.DenseVector[Double]] = Transpose(DenseVector(1.0, 2.0, 3.0, 4.0))\r\n\r\nscala> M\r\nres13: breeze.linalg.DenseMatrix[Double] =\r\n1.0  0.0  0.0  0.0\r\n0.0  2.0  0.0  0.0\r\n0.0  0.0  3.0  0.0\r\n1.0  2.0  3.0  4.0\r\n\r\nscala> M ^ 2\r\nres15: breeze.linalg.DenseMatrix[Double] =\r\n1.0                0.0   0.0                 0.0\r\n0.0                4.0   0.0                 0.0\r\n0.0                0.0   9.0                 0.0\r\n4.999999999999999  12.0  21.000000000000004  16.0\r\n\r\n\r\n\r\n[Breeze_Matrix_Exp.txt](https://github.com/scalanlp/breeze/files/253565/Breeze_Matrix_Exp.txt)","created_at":"2016-05-07T21:03:08Z","updated_at":"2016-05-09T17:40:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f7350820ff2047ceedcf39696aeabb763aefd67","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scalanlp/breeze/pulls/531/commits","review_comments_url":"https://api.github.com/repos/scalanlp/breeze/pulls/531/comments","review_comment_url":"https://api.github.com/repos/scalanlp/breeze/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scalanlp/breeze/issues/531/comments","statuses_url":"https://api.github.com/repos/scalanlp/breeze/statuses/3a7b1c23247e655df8268b01b54fbdd835c21d6a","head":{"label":"claydonkey:backtobreeze","ref":"backtobreeze","sha":"3a7b1c23247e655df8268b01b54fbdd835c21d6a","user":{"login":"claydonkey","id":5519575,"avatar_url":"https://avatars.githubusercontent.com/u/5519575?v=3","gravatar_id":"","url":"https://api.github.com/users/claydonkey","html_url":"https://github.com/claydonkey","followers_url":"https://api.github.com/users/claydonkey/followers","following_url":"https://api.github.com/users/claydonkey/following{/other_user}","gists_url":"https://api.github.com/users/claydonkey/gists{/gist_id}","starred_url":"https://api.github.com/users/claydonkey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claydonkey/subscriptions","organizations_url":"https://api.github.com/users/claydonkey/orgs","repos_url":"https://api.github.com/users/claydonkey/repos","events_url":"https://api.github.com/users/claydonkey/events{/privacy}","received_events_url":"https://api.github.com/users/claydonkey/received_events","type":"User","site_admin":false},"repo":{"id":58123754,"name":"breeze","full_name":"claydonkey/breeze","owner":{"login":"claydonkey","id":5519575,"avatar_url":"https://avatars.githubusercontent.com/u/5519575?v=3","gravatar_id":"","url":"https://api.github.com/users/claydonkey","html_url":"https://github.com/claydonkey","followers_url":"https://api.github.com/users/claydonkey/followers","following_url":"https://api.github.com/users/claydonkey/following{/other_user}","gists_url":"https://api.github.com/users/claydonkey/gists{/gist_id}","starred_url":"https://api.github.com/users/claydonkey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claydonkey/subscriptions","organizations_url":"https://api.github.com/users/claydonkey/orgs","repos_url":"https://api.github.com/users/claydonkey/repos","events_url":"https://api.github.com/users/claydonkey/events{/privacy}","received_events_url":"https://api.github.com/users/claydonkey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/claydonkey/breeze","description":"Breeze is a numerical processing library for Scala.","fork":true,"url":"https://api.github.com/repos/claydonkey/breeze","forks_url":"https://api.github.com/repos/claydonkey/breeze/forks","keys_url":"https://api.github.com/repos/claydonkey/breeze/keys{/key_id}","collaborators_url":"https://api.github.com/repos/claydonkey/breeze/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/claydonkey/breeze/teams","hooks_url":"https://api.github.com/repos/claydonkey/breeze/hooks","issue_events_url":"https://api.github.com/repos/claydonkey/breeze/issues/events{/number}","events_url":"https://api.github.com/repos/claydonkey/breeze/events","assignees_url":"https://api.github.com/repos/claydonkey/breeze/assignees{/user}","branches_url":"https://api.github.com/repos/claydonkey/breeze/branches{/branch}","tags_url":"https://api.github.com/repos/claydonkey/breeze/tags","blobs_url":"https://api.github.com/repos/claydonkey/breeze/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/claydonkey/breeze/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/claydonkey/breeze/git/refs{/sha}","trees_url":"https://api.github.com/repos/claydonkey/breeze/git/trees{/sha}","statuses_url":"https://api.github.com/repos/claydonkey/breeze/statuses/{sha}","languages_url":"https://api.github.com/repos/claydonkey/breeze/languages","stargazers_url":"https://api.github.com/repos/claydonkey/breeze/stargazers","contributors_url":"https://api.github.com/repos/claydonkey/breeze/contributors","subscribers_url":"https://api.github.com/repos/claydonkey/breeze/subscribers","subscription_url":"https://api.github.com/repos/claydonkey/breeze/subscription","commits_url":"https://api.github.com/repos/claydonkey/breeze/commits{/sha}","git_commits_url":"https://api.github.com/repos/claydonkey/breeze/git/commits{/sha}","comments_url":"https://api.github.com/repos/claydonkey/breeze/comments{/number}","issue_comment_url":"https://api.github.com/repos/claydonkey/breeze/issues/comments{/number}","contents_url":"https://api.github.com/repos/claydonkey/breeze/contents/{+path}","compare_url":"https://api.github.com/repos/claydonkey/breeze/compare/{base}...{head}","merges_url":"https://api.github.com/repos/claydonkey/breeze/merges","archive_url":"https://api.github.com/repos/claydonkey/breeze/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/claydonkey/breeze/downloads","issues_url":"https://api.github.com/repos/claydonkey/breeze/issues{/number}","pulls_url":"https://api.github.com/repos/claydonkey/breeze/pulls{/number}","milestones_url":"https://api.github.com/repos/claydonkey/breeze/milestones{/number}","notifications_url":"https://api.github.com/repos/claydonkey/breeze/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/claydonkey/breeze/labels{/name}","releases_url":"https://api.github.com/repos/claydonkey/breeze/releases{/id}","deployments_url":"https://api.github.com/repos/claydonkey/breeze/deployments","created_at":"2016-05-05T10:38:29Z","updated_at":"2016-05-05T10:38:31Z","pushed_at":"2016-05-08T16:47:21Z","git_url":"git://github.com/claydonkey/breeze.git","ssh_url":"git@github.com:claydonkey/breeze.git","clone_url":"https://github.com/claydonkey/breeze.git","svn_url":"https://github.com/claydonkey/breeze","homepage":"www.scalanlp.org","size":25987,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scalanlp:master","ref":"master","sha":"fb0c56fa18cc20ad8c191c362aae2f0d25786bf7","user":{"login":"scalanlp","id":103090,"avatar_url":"https://avatars.githubusercontent.com/u/103090?v=3","gravatar_id":"","url":"https://api.github.com/users/scalanlp","html_url":"https://github.com/scalanlp","followers_url":"https://api.github.com/users/scalanlp/followers","following_url":"https://api.github.com/users/scalanlp/following{/other_user}","gists_url":"https://api.github.com/users/scalanlp/gists{/gist_id}","starred_url":"https://api.github.com/users/scalanlp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalanlp/subscriptions","organizations_url":"https://api.github.com/users/scalanlp/orgs","repos_url":"https://api.github.com/users/scalanlp/repos","events_url":"https://api.github.com/users/scalanlp/events{/privacy}","received_events_url":"https://api.github.com/users/scalanlp/received_events","type":"Organization","site_admin":false},"repo":{"id":246644,"name":"breeze","full_name":"scalanlp/breeze","owner":{"login":"scalanlp","id":103090,"avatar_url":"https://avatars.githubusercontent.com/u/103090?v=3","gravatar_id":"","url":"https://api.github.com/users/scalanlp","html_url":"https://github.com/scalanlp","followers_url":"https://api.github.com/users/scalanlp/followers","following_url":"https://api.github.com/users/scalanlp/following{/other_user}","gists_url":"https://api.github.com/users/scalanlp/gists{/gist_id}","starred_url":"https://api.github.com/users/scalanlp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalanlp/subscriptions","organizations_url":"https://api.github.com/users/scalanlp/orgs","repos_url":"https://api.github.com/users/scalanlp/repos","events_url":"https://api.github.com/users/scalanlp/events{/privacy}","received_events_url":"https://api.github.com/users/scalanlp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scalanlp/breeze","description":"Breeze is a numerical processing library for Scala.","fork":false,"url":"https://api.github.com/repos/scalanlp/breeze","forks_url":"https://api.github.com/repos/scalanlp/breeze/forks","keys_url":"https://api.github.com/repos/scalanlp/breeze/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scalanlp/breeze/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scalanlp/breeze/teams","hooks_url":"https://api.github.com/repos/scalanlp/breeze/hooks","issue_events_url":"https://api.github.com/repos/scalanlp/breeze/issues/events{/number}","events_url":"https://api.github.com/repos/scalanlp/breeze/events","assignees_url":"https://api.github.com/repos/scalanlp/breeze/assignees{/user}","branches_url":"https://api.github.com/repos/scalanlp/breeze/branches{/branch}","tags_url":"https://api.github.com/repos/scalanlp/breeze/tags","blobs_url":"https://api.github.com/repos/scalanlp/breeze/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scalanlp/breeze/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scalanlp/breeze/git/refs{/sha}","trees_url":"https://api.github.com/repos/scalanlp/breeze/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scalanlp/breeze/statuses/{sha}","languages_url":"https://api.github.com/repos/scalanlp/breeze/languages","stargazers_url":"https://api.github.com/repos/scalanlp/breeze/stargazers","contributors_url":"https://api.github.com/repos/scalanlp/breeze/contributors","subscribers_url":"https://api.github.com/repos/scalanlp/breeze/subscribers","subscription_url":"https://api.github.com/repos/scalanlp/breeze/subscription","commits_url":"https://api.github.com/repos/scalanlp/breeze/commits{/sha}","git_commits_url":"https://api.github.com/repos/scalanlp/breeze/git/commits{/sha}","comments_url":"https://api.github.com/repos/scalanlp/breeze/comments{/number}","issue_comment_url":"https://api.github.com/repos/scalanlp/breeze/issues/comments{/number}","contents_url":"https://api.github.com/repos/scalanlp/breeze/contents/{+path}","compare_url":"https://api.github.com/repos/scalanlp/breeze/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scalanlp/breeze/merges","archive_url":"https://api.github.com/repos/scalanlp/breeze/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scalanlp/breeze/downloads","issues_url":"https://api.github.com/repos/scalanlp/breeze/issues{/number}","pulls_url":"https://api.github.com/repos/scalanlp/breeze/pulls{/number}","milestones_url":"https://api.github.com/repos/scalanlp/breeze/milestones{/number}","notifications_url":"https://api.github.com/repos/scalanlp/breeze/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scalanlp/breeze/labels{/name}","releases_url":"https://api.github.com/repos/scalanlp/breeze/releases{/id}","deployments_url":"https://api.github.com/repos/scalanlp/breeze/deployments","created_at":"2009-07-08T23:22:52Z","updated_at":"2016-05-09T09:00:51Z","pushed_at":"2016-05-08T16:47:21Z","git_url":"git://github.com/scalanlp/breeze.git","ssh_url":"git@github.com:scalanlp/breeze.git","clone_url":"https://github.com/scalanlp/breeze.git","svn_url":"https://github.com/scalanlp/breeze","homepage":"www.scalanlp.org","size":27331,"stargazers_count":1522,"watchers_count":1522,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":406,"mirror_url":null,"open_issues_count":73,"forks":406,"open_issues":73,"watchers":1522,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scalanlp/breeze/pulls/531"},"html":{"href":"https://github.com/scalanlp/breeze/pull/531"},"issue":{"href":"https://api.github.com/repos/scalanlp/breeze/issues/531"},"comments":{"href":"https://api.github.com/repos/scalanlp/breeze/issues/531/comments"},"review_comments":{"href":"https://api.github.com/repos/scalanlp/breeze/pulls/531/comments"},"review_comment":{"href":"https://api.github.com/repos/scalanlp/breeze/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scalanlp/breeze/pulls/531/commits"},"statuses":{"href":"https://api.github.com/repos/scalanlp/breeze/statuses/3a7b1c23247e655df8268b01b54fbdd835c21d6a"}}}}