본문 바로가기

학교 공부/프로그래밍원리

HW3 -(4) StackedArray 구현하기

final class StackedArray(val values: Array[NDArray]) extends NDArray {
  val ndim: Int = this.getShape.length

  val getShape: Array[Int] = {
    def func(res: Array[Int] = Array(), x: Array[NDArray]): Array[Int] = {
      if (x(0).ndim == 1) res ++ Array(x.length) ++ Array(x(0).values.length)
      else func(res ++ Array(x.length), x(0).values)
    }
    func(this.values)
  }

  def getArr(i: Int): NDArray = {
    if (i >= values.length) NNException("OutOfRange")
    else values(i)}

  def get(i: Int): Float = {
    if (this.ndim == 1) values(i)
    else NNException("Not a Vector") //raise NNException
  }

  def reshape(shape: Int*): NDArray = ???

  def reduceLeft[T](f: (Float, Float) => Float): T = ???



  def binOp(f: (Float, Float) => Float, that: NDArray): NDArray = ???

  def equals(that: NDArray): Boolean = ???
}




object StackedArray extends NDArrayOps[StackedArray] {
  def apply(shape: Seq[Int], values: Seq[Float]): StackedArray = ???

  def fill(shape: Seq[Int], value: Float): StackedArray = ???

  def stack(values: Seq[NDArray]): StackedArray = ???

'학교 공부 > 프로그래밍원리' 카테고리의 다른 글

12/6 다시 푸는 Assignment 1  (0) 2022.12.06
HW4-(1)  (0) 2022.12.02
HW3 - (3) Matrix 구현하기  (0) 2022.11.26
HW 3- (2) reshape 구현하기  (0) 2022.11.26
HW3 - (1)  (0) 2022.11.25