diff --git a/.swiftformat b/.swiftformat index 77a1601..b8ca16f 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1 +1,2 @@ ---disable unusedArguments \ No newline at end of file +--disable unusedArguments +--disable spaceAroundOperators \ No newline at end of file diff --git a/README.md b/README.md index 70cd454..3135773 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Sources/NDArray/Ops/subscript.swift b/Sources/NDArray/Ops/subscript.swift index 18d0483..a71f6e1 100644 --- a/Sources/NDArray/Ops/subscript.swift +++ b/Sources/NDArray/Ops/subscript.swift @@ -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) - } -} - ///////////////////////////////////////////////////////////////////////////////////////////// // .. ///////////////////////////////////////////////////////////////////////////////////////////// @@ -350,4 +300,54 @@ public extension Int { static func .... (lhs: Int, rhs: Int) -> Slice { Slice(start: lhs, stride: rhs) } -} \ No newline at end of file +} + +///////////////////////////////////////////////////////////////////////////////////////////// +// |> +///////////////////////////////////////////////////////////////////////////////////////////// + +// 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) +// } +// } \ No newline at end of file diff --git a/Tests/NDArrayTests/NDArrayTests.swift b/Tests/NDArrayTests/NDArrayTests.swift index 14b74a7..5c565f4 100644 --- a/Tests/NDArrayTests/NDArrayTests.swift +++ b/Tests/NDArrayTests/NDArrayTests.swift @@ -291,8 +291,8 @@ final class NDArrayTests: XCTestCase { var a = NDArray([1, 2, 3, 4], shape: [4]) var b = a - a[0|>] = NDArray([1, 1, 1, 1]) - b[0|>] = NDArray([2, 2, 2, 2]) + a[0..] = NDArray([1, 1, 1, 1]) + b[0..] = NDArray([2, 2, 2, 2]) XCTAssertEqual(a.data.value, [1, 1, 1, 1]) XCTAssertEqual(b.data.value, [2, 2, 2, 2]) @@ -302,8 +302,8 @@ final class NDArrayTests: XCTestCase { var a = NDArray([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]) @@ -313,8 +313,8 @@ final class NDArrayTests: XCTestCase { var a = NDArray([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]) @@ -324,8 +324,8 @@ final class NDArrayTests: XCTestCase { var a = NDArray([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]) @@ -438,7 +438,7 @@ final class NDArrayTests: XCTestCase { func testNegativeStride2() { let a = NDArray([1, 2, 3, 4, 5]) - let b = a[||>-1] + let b = a[....-1] XCTAssertEqual(a.data.value, b.copy().data.value.reversed()) } @@ -446,7 +446,7 @@ final class NDArrayTests: XCTestCase { func testNegativeStride3() { let a = NDArray([1, 2, 3, 4, 5]) - let b = a[|>1 |> -2] + let b = a[..1..-2] XCTAssertEqual(b.copy().data.value, [5, 3]) }