Skip to content

Commit

Permalink
optimize some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwh committed May 16, 2015
1 parent d5ec11e commit 58fecfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions math/src/main/scala/breeze/linalg/functions/CanPad.scala
@@ -1,5 +1,7 @@
package breeze.linalg

import java.util

import breeze.macros.expand
import breeze.linalg.Options._
import breeze.stats.{median, mean}
Expand Down Expand Up @@ -142,16 +144,21 @@ object CanPadLeft {
}
}

def padLeft1ImplZero[T]
def padLeft1ImplZero
(v: DenseVector[T], optDim: Dimensions1): DenseVector[T] = {
padLeft1ImplFixed(v, optDim, implicitly[Semiring[T]].zero)
}

def padLeft1ImplFixed[T](v: DenseVector[T], optDim: Dimensions1, padValue: T): DenseVector[T] = {
def padLeft1ImplFixed(v: DenseVector[T], optDim: Dimensions1, padValue: T): DenseVector[T] = {
require( optDim.n1 > 0, "Cannot pad to zero or negative length!")
v.length match {
case optDim.n1 => v.copy
case num: Int if num < optDim.n1 => DenseVector( Array.tabulate(optDim.n1 - num)(p => padValue) ++ v.toArray )
case num: Int if num < optDim.n1 =>
val res = new Array[T](optDim.n1)
util.Arrays.fill(res, padValue)
val r = new DenseVector(res)
r((optDim.n1 - num) until optDim.n1) := v
r
case num: Int if optDim.n1 < num => v(v.length - optDim.n1 until v.length).copy //function should return a copy
case _ => throw new IllegalArgumentException("(n) specification incorrect: " + optDim.toString + " !")
}
Expand Down
@@ -1,6 +1,7 @@
package breeze.signal.support

import edu.emory.mathcs.jtransforms.fft.{DoubleFFT_1D, DoubleFFT_2D}
import spire.syntax.cfor._
import breeze.linalg.{DenseVector, DenseMatrix}
import breeze.math.Complex

Expand Down Expand Up @@ -38,7 +39,9 @@ object JTransformsSupport {

private[signal] def tempToDenseVector(tempArr: Array[Double]): DenseVector[Complex] = {
val tempRet = DenseVector.zeros[Complex](tempArr.length/2)
for (n <- 0 until tempRet.length) tempRet(n) = new Complex( tempArr(2*n), tempArr(2*n+1))
cforRange(0 until tempRet.length) { n =>
tempRet(n) = new Complex( tempArr(2*n), tempArr(2*n+1))
}
tempRet
}

Expand Down

0 comments on commit 58fecfa

Please sign in to comment.