Skip to content

Commit

Permalink
fix: f32 convert to f64 pass all func
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvictor committed Nov 8, 2024
1 parent b62b5ce commit 3052ef3
Show file tree
Hide file tree
Showing 14 changed files with 7,912 additions and 452 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,35 @@ jobs:
name: wheels
path: dist

linux-arm:
runs-on: ubuntu-latest
strategy:
matrix:
target: [aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
container: ghcr.io/rust-cross/manylinux_2_28-cross:aarch64
rust-toolchain: stable-aarch64-unknown-linux-gnu
env:
DEPS_PATH: ${{ github.workspace }}/dependencies
TA_INCLUDE_PATH: ${{ github.workspace }}/dependencies/include
TA_LIBRARY_PATH: ${{ github.workspace }}/dependencies/lib
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist
# linux-arm:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# target: [aarch64]
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "3.10"
# - name: Setup QEMU
# uses: docker/setup-qemu-action@v1
# - name: Build wheels
# uses: PyO3/maturin-action@v1
# with:
# target: ${{ matrix.target }}
# args: --release --out dist --find-interpreter
# sccache: 'true'
# container: ghcr.io/rust-cross/manylinux_2_28-cross:aarch64
# rust-toolchain: stable-aarch64-unknown-linux-gnu
# env:
# DEPS_PATH: ${{ github.workspace }}/dependencies
# TA_INCLUDE_PATH: ${{ github.workspace }}/dependencies/include
# TA_LIBRARY_PATH: ${{ github.workspace }}/dependencies/lib
# - name: Upload wheels
# uses: actions/upload-artifact@v3
# with:
# name: wheels
# path: dist


windows:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polars_talib"
version = "0.1.3"
version = "0.1.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
12 changes: 6 additions & 6 deletions src/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::utils::{get_series_f64_ptr, ta_code2err};
use crate::utils::{cast_series_to_f64, get_series_f64_ptr, ta_code2err};
use polars::prelude::*;
use pyo3_polars::derive::polars_expr;
use talib::cycle::{ta_ht_dcperiod, ta_ht_dcphase, ta_ht_phasor, ta_ht_sine, ta_ht_trendmode};

#[polars_expr(output_type=Float64)]
fn ht_dcperiod(inputs: &[Series]) -> PolarsResult<Series> {
let mut real = inputs[0].to_float()?.rechunk();
let mut real = cast_series_to_f64(&inputs[0])?;
let (real_ptr, _real) = get_series_f64_ptr(&mut real)?;
let res = ta_ht_dcperiod(real_ptr, real.len());
match res {
Expand All @@ -16,7 +16,7 @@ fn ht_dcperiod(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn ht_dcphase(inputs: &[Series]) -> PolarsResult<Series> {
let mut real = inputs[0].to_float()?.rechunk();
let mut real = cast_series_to_f64(&inputs[0])?;
let (real_ptr, _real) = get_series_f64_ptr(&mut real)?;
let res = ta_ht_dcphase(real_ptr, real.len());
match res {
Expand All @@ -34,7 +34,7 @@ pub fn ht_phasor_output(_: &[Field]) -> PolarsResult<Field> {

#[polars_expr(output_type_func=ht_phasor_output)]
fn ht_phasor(inputs: &[Series]) -> PolarsResult<Series> {
let mut real = inputs[0].to_float()?.rechunk();
let mut real = cast_series_to_f64(&inputs[0])?;
let (real_ptr, _real) = get_series_f64_ptr(&mut real)?;
let res = ta_ht_phasor(real_ptr, real.len());
match res {
Expand All @@ -57,7 +57,7 @@ pub fn ht_sine_output(_: &[Field]) -> PolarsResult<Field> {

#[polars_expr(output_type_func=ht_sine_output)]
fn ht_sine(inputs: &[Series]) -> PolarsResult<Series> {
let mut real = inputs[0].to_float()?.rechunk();
let mut real = cast_series_to_f64(&inputs[0])?;
let (real_ptr, _real) = get_series_f64_ptr(&mut real)?;
let res = ta_ht_sine(real_ptr, real.len());
match res {
Expand All @@ -73,7 +73,7 @@ fn ht_sine(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Int32)]
fn ht_trendmode(inputs: &[Series]) -> PolarsResult<Series> {
let mut real = inputs[0].to_float()?.rechunk();
let mut real = cast_series_to_f64(&inputs[0])?;
let (real_ptr, _real) = get_series_f64_ptr(&mut real)?;
let res = ta_ht_trendmode(real_ptr, real.len());
match res {
Expand Down
62 changes: 31 additions & 31 deletions src/math.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{get_series_f64_ptr, ta_code2err};
use crate::utils::{cast_series_to_f64, get_series_f64_ptr, ta_code2err};
use polars::prelude::*;
use pyo3_polars::derive::polars_expr;
use talib::common::TimePeriodKwargs;
Expand All @@ -14,8 +14,8 @@ use talib::math::{

#[polars_expr(output_type=Float64)]
fn add(inputs: &[Series]) -> PolarsResult<Series> {
let input1 = &mut inputs[0].to_float()?.rechunk();
let input2 = &mut inputs[1].to_float()?.rechunk();
let input1 = &mut cast_series_to_f64(&inputs[0])?;
let input2 = &mut cast_series_to_f64(&inputs[1])?;
let (input1_ptr, _input1) = get_series_f64_ptr(input1)?;
let (input2_ptr, _input2) = get_series_f64_ptr(input2)?;
let len = input1.len();
Expand All @@ -28,8 +28,8 @@ fn add(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn div(inputs: &[Series]) -> PolarsResult<Series> {
let input1 = &mut inputs[0].to_float()?.rechunk();
let input2 = &mut inputs[1].to_float()?.rechunk();
let input1 = &mut cast_series_to_f64(&inputs[0])?;
let input2 = &mut cast_series_to_f64(&inputs[1])?;
let (input1_ptr, _input1) = get_series_f64_ptr(input1)?;
let (input2_ptr, _input2) = get_series_f64_ptr(input2)?;
let len = input1.len();
Expand All @@ -42,7 +42,7 @@ fn div(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn max(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;
let len = input.len();
let res = ta_max(input_ptr, len, &kwargs);
Expand All @@ -54,7 +54,7 @@ fn max(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {

#[polars_expr(output_type=Int32)]
fn maxindex(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;
let len = input.len();
let res = ta_maxindex(input_ptr, len, &kwargs);
Expand All @@ -66,7 +66,7 @@ fn maxindex(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series>

#[polars_expr(output_type=Float64)]
fn min(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;
let len = input.len();
let res = ta_min(input_ptr, len, &kwargs);
Expand All @@ -78,7 +78,7 @@ fn min(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {

#[polars_expr(output_type=Int32)]
fn minindex(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;
let len = input.len();
let res = ta_minindex(input_ptr, len, &kwargs);
Expand All @@ -97,7 +97,7 @@ pub fn minmax_output(_: &[Field]) -> PolarsResult<Field> {

#[polars_expr(output_type_func=minmax_output)]
fn minmax(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -122,7 +122,7 @@ pub fn minmaxindex_output(_: &[Field]) -> PolarsResult<Field> {

#[polars_expr(output_type_func=minmaxindex_output)]
fn minmaxindex(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -140,8 +140,8 @@ fn minmaxindex(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Seri

#[polars_expr(output_type=Float64)]
fn mult(inputs: &[Series]) -> PolarsResult<Series> {
let input1 = &mut inputs[0].to_float()?.rechunk();
let input2 = &mut inputs[1].to_float()?.rechunk();
let input1 = &mut cast_series_to_f64(&inputs[0])?;
let input2 = &mut cast_series_to_f64(&inputs[1])?;
let (input1_ptr, _input1) = get_series_f64_ptr(input1)?;
let (input2_ptr, _input2) = get_series_f64_ptr(input2)?;
let len = input1.len();
Expand All @@ -154,8 +154,8 @@ fn mult(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn sub(inputs: &[Series]) -> PolarsResult<Series> {
let input1 = &mut inputs[0].to_float()?.rechunk();
let input2 = &mut inputs[1].to_float()?.rechunk();
let input1 = &mut cast_series_to_f64(&inputs[0])?;
let input2 = &mut cast_series_to_f64(&inputs[1])?;
let (input1_ptr, _input1) = get_series_f64_ptr(input1)?;
let (input2_ptr, _input2) = get_series_f64_ptr(input2)?;
let len = input1.len();
Expand All @@ -168,7 +168,7 @@ fn sub(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn sum(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -181,7 +181,7 @@ fn sum(inputs: &[Series], kwargs: TimePeriodKwargs) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn acos(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -197,7 +197,7 @@ fn acos(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn asin(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -213,7 +213,7 @@ fn asin(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn atan(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -229,7 +229,7 @@ fn atan(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn ceil(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -245,7 +245,7 @@ fn ceil(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn cos(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -261,7 +261,7 @@ fn cos(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn cosh(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -277,7 +277,7 @@ fn cosh(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn exp(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -290,7 +290,7 @@ fn exp(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn floor(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -303,7 +303,7 @@ fn floor(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn ln(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -316,7 +316,7 @@ fn ln(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn log10(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -329,7 +329,7 @@ fn log10(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn sin(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -342,7 +342,7 @@ fn sin(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn sinh(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -355,7 +355,7 @@ fn sinh(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn sqrt(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -368,7 +368,7 @@ fn sqrt(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn tan(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand All @@ -381,7 +381,7 @@ fn tan(inputs: &[Series]) -> PolarsResult<Series> {

#[polars_expr(output_type=Float64)]
fn tanh(inputs: &[Series]) -> PolarsResult<Series> {
let input = &mut inputs[0].to_float()?.rechunk();
let input = &mut cast_series_to_f64(&inputs[0])?;
let (input_ptr, _input) = get_series_f64_ptr(input)?;

let len = input.len();
Expand Down
Loading

0 comments on commit 3052ef3

Please sign in to comment.