Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
remove |> operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Garcia committed Aug 13, 2019
1 parent 1de483f commit f8af4ce
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 64 deletions.
3 changes: 2 additions & 1 deletion .swiftformat
@@ -1 +1,2 @@
--disable unusedArguments
--disable unusedArguments
--disable spaceAroundOperators
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -12,13 +12,13 @@ NDArray is a multidimensional array library written in Swift that aims to become

Tutorial | Last Updated |
-------- | ------------ |
[Basic API](https://colab.research.google.com/drive/1aULWtrtj6WsNeJe_vBnr_hswy0JIYDt_) | August 2019 |
[Basic API](https://colab.research.google.com/drive/1aULWtrtj6WsNeJe_vBnr_hswy0JIYDt_) | August 13 2019 |


## Installation
You can install it via SwiftPM via:
```swift
.package(url: "https://github.com/cgarciae/NDArray", from: "0.0.15")
.package(url: "https://github.com/cgarciae/NDArray", from: "0.0.16")
```
It might work on other compatible package managers. This package is only tested in Swift 5.1, compatibility with previous version is not guaranteed.

Expand Down
102 changes: 51 additions & 51 deletions Sources/NDArray/Ops/subscript.swift
Expand Up @@ -239,56 +239,6 @@ public struct Slice: ArrayExpression {
}
}

/////////////////////////////////////////////////////////////////////////////////////////////
// |>
/////////////////////////////////////////////////////////////////////////////////////////////

postfix operator |>
prefix operator |>
prefix operator |>-
infix operator |>: AdditionPrecedence
infix operator ||>
prefix operator ||>
prefix operator ||>-

public extension Int {
static postfix func |> (lhs: Int) -> Slice {
Slice(start: lhs)
}

static prefix func |> (rhs: Int) -> Slice {
Slice(end: rhs)
}

static prefix func |>- (rhs: Int) -> Slice {
Slice(end: -rhs)
}

static func |> (lhs: Int, rhs: Int) -> Slice {
Slice(start: lhs, end: rhs)
}

static func |> (lhs: Slice, rhs: Int) -> Slice {
Slice(start: lhs.start, end: lhs.end, stride: rhs)
}

static func |> (lhs: Int, rhs: Slice) -> Slice {
Slice(start: lhs, end: rhs.start, stride: rhs.end!)
}

static prefix func ||> (rhs: Int) -> Slice {
Slice(stride: rhs)
}

static prefix func ||>- (rhs: Int) -> Slice {
Slice(stride: -rhs)
}

static func ||> (lhs: Int, rhs: Int) -> Slice {
Slice(start: lhs, stride: rhs)
}
}

/////////////////////////////////////////////////////////////////////////////////////////////
// ..
/////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -350,4 +300,54 @@ public extension Int {
static func .... (lhs: Int, rhs: Int) -> Slice {
Slice(start: lhs, stride: rhs)
}
}
}

/////////////////////////////////////////////////////////////////////////////////////////////
// |>
/////////////////////////////////////////////////////////////////////////////////////////////

// postfix operator |>
// prefix operator |>
// prefix operator |>-
// infix operator |>: AdditionPrecedence
// infix operator ||>
// prefix operator ||>
// prefix operator ||>-

// public extension Int {
// static postfix func |> (lhs: Int) -> Slice {
// Slice(start: lhs)
// }

// static prefix func |> (rhs: Int) -> Slice {
// Slice(end: rhs)
// }

// static prefix func |>- (rhs: Int) -> Slice {
// Slice(end: -rhs)
// }

// static func |> (lhs: Int, rhs: Int) -> Slice {
// Slice(start: lhs, end: rhs)
// }

// static func |> (lhs: Slice, rhs: Int) -> Slice {
// Slice(start: lhs.start, end: lhs.end, stride: rhs)
// }

// static func |> (lhs: Int, rhs: Slice) -> Slice {
// Slice(start: lhs, end: rhs.start, stride: rhs.end!)
// }

// static prefix func ||> (rhs: Int) -> Slice {
// Slice(stride: rhs)
// }

// static prefix func ||>- (rhs: Int) -> Slice {
// Slice(stride: -rhs)
// }

// static func ||> (lhs: Int, rhs: Int) -> Slice {
// Slice(start: lhs, stride: rhs)
// }
// }
20 changes: 10 additions & 10 deletions Tests/NDArrayTests/NDArrayTests.swift
Expand Up @@ -291,8 +291,8 @@ final class NDArrayTests: XCTestCase {
var a = NDArray<Int>([1, 2, 3, 4], shape: [4])
var b = a

a[0|>] = NDArray<Int>([1, 1, 1, 1])
b[0|>] = NDArray<Int>([2, 2, 2, 2])
a[0..] = NDArray<Int>([1, 1, 1, 1])
b[0..] = NDArray<Int>([2, 2, 2, 2])

XCTAssertEqual(a.data.value, [1, 1, 1, 1])
XCTAssertEqual(b.data.value, [2, 2, 2, 2])
Expand All @@ -302,8 +302,8 @@ final class NDArrayTests: XCTestCase {
var a = NDArray<Int>([1, 2, 3, 4], shape: [4])
var b = a

a[0|>] = NDArray(1)
b[0|>] = NDArray(2)
a[0..] = NDArray(1)
b[0..] = NDArray(2)

XCTAssertEqual(a.data.value, [1, 1, 1, 1])
XCTAssertEqual(b.data.value, [2, 2, 2, 2])
Expand All @@ -313,8 +313,8 @@ final class NDArrayTests: XCTestCase {
var a = NDArray<Int>([1, 2, 3, 4], shape: [4])
var b = a

a[0|>] = NDArray(1)
b[0|>] = NDArray(2)
a[0..] = NDArray(1)
b[0..] = NDArray(2)

XCTAssertEqual(a.data.value, [1, 1, 1, 1])
XCTAssertEqual(b.data.value, [2, 2, 2, 2])
Expand All @@ -324,8 +324,8 @@ final class NDArrayTests: XCTestCase {
var a = NDArray<Int>([1, 2, 3, 4], shape: [4])
var b = a

a[0|>] = [1, 1, 1, 1]
b[0|>] = [2, 2, 2, 2]
a[0..] = [1, 1, 1, 1]
b[0..] = [2, 2, 2, 2]

XCTAssertEqual(a.data.value, [1, 1, 1, 1])
XCTAssertEqual(b.data.value, [2, 2, 2, 2])
Expand Down Expand Up @@ -438,15 +438,15 @@ final class NDArrayTests: XCTestCase {
func testNegativeStride2() {
let a = NDArray<Int>([1, 2, 3, 4, 5])

let b = a[||>-1]
let b = a[....-1]

XCTAssertEqual(a.data.value, b.copy().data.value.reversed())
}

func testNegativeStride3() {
let a = NDArray<Int>([1, 2, 3, 4, 5])

let b = a[|>1 |> -2]
let b = a[..1..-2]

XCTAssertEqual(b.copy().data.value, [5, 3])
}
Expand Down

0 comments on commit f8af4ce

Please sign in to comment.