This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coordinates = [] | |
word = "" | |
polyline.each_byte do |b| | |
# Add the character b to the current chunk | |
word << b | |
next unless b < 0x5f # While we are below the _ ascii code | |
# Add the chunk to the list of coordinates represented by a string | |
coordinates << word | |
word = "" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encode(points, precision = 1e5) | |
result = "" | |
last_lat = last_lng = last_timestamp = 0 | |
# Convert each point (lat, lng, ts) to a string | |
points.each do |point| | |
# Convert to integer | |
lat = (point[0] * precision).round | |
lng = (point[1] * precision).round | |
timestamp = point[2] | |
# Compute the difference with the previous point |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ListZipper<T> { | |
private var leftList: [T] = [] | |
private var rightList: [T] = [] | |
/// Cursor to the selected Track | |
var cursor: T? = nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init(from list: [T] = []) { | |
cursor = list.first | |
rightList = list | |
} | |
/// Convert to a swift array | |
func toList() -> [T] { | |
if let c = cursor { | |
return leftList + [c] + rightList.reversed() | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Select the left element if available | |
mutating func left() { | |
guard leftList.isNotEmpty else {return} | |
if let c = cursor {rightList.append(c)} | |
cursor = leftList.popLast() | |
} | |
/// Select the right element if available | |
mutating func right() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Insert a new track | |
mutating func insert(element: T) { | |
if let c = cursor {leftList.append(c)} | |
cursor = element | |
} | |
/// Remove the current pointed track | |
mutating func remove() { | |
guard let _ = cursor else {return} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Map a function to the tracks | |
func map<R>(f: (T) -> R) -> ListZipper<R> { | |
var zipper = ListZipper<R>() | |
zipper.leftList = leftList.map(f) | |
zipper.cursor = cursor.map(f) | |
zipper.rightList = rightList.map(f) | |
return zipper | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var zippy = ListZipper<String>(from: ["I", "love", "pancakes"]) | |
print(zippy.cursor!) // I | |
zippy.right() // move to the right | |
print(zippy.cursor!) // love | |
zippy.cursor = "hate" | |
print(zippy.toList().joined(separator: " ")) // I hate pancakes | |
zippy.remove() | |
zippy.cursor = "Eat" | |
print(zippy.toList().joined(separator: " ")) // Eat pancakes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import onnxruntime as rt | |
import onnx | |
import numpy as np | |
import torch | |
import torch.nn as nn | |
import torch.nn | |
import torch.onnx | |
def onnx_export(model: torch.nn.Module, input_shape, filename: str, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MIT LICENSE: Copy past as much as you want :) | |
// | |
// Your signal, array of length 1024 | |
let signal: [Float] = (0 ... 1024) | |
// --- INITIALIZATION | |
// The length of the input | |
length = vDSP_Length(signal.count) |
OlderNewer