diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b29812 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3ebcc4b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 uhooi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..ed7d5d3 --- /dev/null +++ b/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version: 5.6 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "Sigmoid", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "Sigmoid", + targets: ["Sigmoid"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "Sigmoid", + dependencies: []), + .testTarget( + name: "SigmoidTests", + dependencies: ["Sigmoid"]), + ] +) diff --git a/README.md b/README.md index 3ba7a3a..bda8e05 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ +[![CI](https://github.com/yoshikaz1228/Sigmoid/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/yoshikaz1228/Sigmoid/actions/workflows/main.yml) +[![Release](https://img.shields.io/github/v/release/yoshikaz1228/Sigmoid)](https://github.com/yoshikaz1228/Sigmoid/releases/latest) +[![License](https://img.shields.io/github/license/yoshikaz1228/Sigmoid)](https://github.com/yoshikaz1228/Sigmoid/blob/main/LICENSE) + # Sigmoid implement sigmoid for swift. ## For example ``` -var sigmoid = Sigmoid() -print(sigmoid.sigmoid(x:0.2)) +let a = 1.0 +let b = a.sigmoid() ``` diff --git a/Sources/Sigmoid/Sigmoid.swift b/Sources/Sigmoid/Sigmoid.swift new file mode 100644 index 0000000..c9a4044 --- /dev/null +++ b/Sources/Sigmoid/Sigmoid.swift @@ -0,0 +1,13 @@ +// +// File.swift +// Sigmoid +// +// Created by Yoshikaz Matsubara on 2022/08/07. +// + +import Foundation +extension Double { + public func sigmoid() -> Double { + return 1/(1+pow(M_E,-1.0 * self)) + } +} diff --git a/Tests/SigmoidTests/SigmoidTests.swift b/Tests/SigmoidTests/SigmoidTests.swift new file mode 100644 index 0000000..748fbb0 --- /dev/null +++ b/Tests/SigmoidTests/SigmoidTests.swift @@ -0,0 +1,18 @@ +import XCTest +@testable import Sigmoid + +final class SigmoidTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + var double: Double = 0.0 + XCTAssertEqual(double.sigmoid(), 0.5) + + double = 1.0 + XCTAssertEqual(double.sigmoid(), 0.7310585786300049) + + double = -1.0 + XCTAssertEqual(double.sigmoid(), 0.2689414213699951) + } +} diff --git a/sigmoid.swift b/sigmoid.swift deleted file mode 100644 index bbaa8cc..0000000 --- a/sigmoid.swift +++ /dev/null @@ -1,8 +0,0 @@ -import Foundation -class Sigmoid { - init() { - } - func sigmoid(x: Double) -> Double { - return 1/(1+pow(M_E,-1.0 * x)) - } -} diff --git a/workflows/main.yml b/workflows/main.yml new file mode 100644 index 0000000..2e82c57 --- /dev/null +++ b/workflows/main.yml @@ -0,0 +1,25 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + DEVELOPER_DIR: /Applications/Xcode_13.4.1.app + +jobs: + build: + runs-on: macOS-latest + steps: + - uses: actions/checkout@v2 + - name: Build + run: swift build -v + + test: + runs-on: macOS-latest + steps: + - uses: actions/checkout@v2 + - name: Test + run: swift test -v