This file contains hidden or 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 logging | |
import os | |
import pathlib | |
import re | |
import time | |
from typing import Any | |
import jsonlines | |
import openai | |
import torch |
This file contains hidden or 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
/// Computes the greatest common divisor of two integers using Euclid's algorithm | |
/// (https://en.wikipedia.org/wiki/Euclidean_algorithm). | |
/// | |
/// # Example | |
/// | |
/// ```rust | |
/// assert_eq!(gcd(3, 5), 1); | |
/// | |
/// assert_eq!(gcd(2 * 3 * 5 * 11 * 17, 3 * 7 * 11 * 13 * 19), 3 * 11); | |
/// ``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
/// Returns an [`Flatten`] - an object that flattens a given iterable. | |
/// | |
/// [`Flatten`]: struct.Flatten | |
pub fn flatten<I>(iter: I) -> Flatten<I::IntoIter> | |
where | |
I: IntoIterator, | |
I::Item: IntoIterator, | |
{ | |
Flatten::new(iter.into_iter()) | |
} |
This file contains hidden or 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
trait MaxValue { | |
fn max_value() -> Self; | |
} | |
macro_rules! max_impl { | |
($t:ty) => { | |
impl crate::MaxValue for $t { | |
fn max_value() -> Self { | |
<$t>::max_value() | |
} |
This file contains hidden or 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
#[macro_export] | |
macro_rules! avec { | |
($($element:expr),*) => {{ | |
const COUNT: usize = crate::count![@COUNT; $($element),*]; | |
#[allow(unused_mut)] | |
let mut vs = Vec::with_capacity(COUNT); | |
$(vs.push($element);)* | |
vs | |
}}; |
This file contains hidden or 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
#[derive(Debug)] | |
pub struct StrSplit<'haystack, D> { | |
remainder: Option<&'haystack str>, | |
delimiter: D, | |
} | |
impl<'haystack, D> StrSplit<'haystack, D> { | |
pub fn new(haystack: &'haystack str, delimiter: D) -> Self { | |
Self { | |
remainder: Some(haystack), |
This file contains hidden or 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
from typing import Generic | |
from typing import Iterable | |
from typing import TypeVar | |
# Generic type. | |
T = TypeVar('T') | |
class Vector(Generic[T]): | |
"""A light-weight Vector utility class, used to perform various operations |
This file contains hidden or 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
use std::any::{Any, TypeId}; | |
trait InstanceOf | |
where | |
Self: Any | |
{ | |
fn instance_of<U: ?Sized + Any>(&self) -> bool { | |
TypeId::of::<Self>() == TypeId::of::<U>() | |
} | |
} |
NewerOlder