Closed vron closed 2 years ago
Hi,
Right, that's by design, as Rust is generally strongly typed. However there is a work around which is sort of ok...
Take in a String or Array2parse::<i32>()
I do have the reverse though:
fn example(name: Array2<String>) -> Result<Array2<Variant>, Box<dyn std::error::Error>> {
// ...
// some code before
Ok(Array2::from_shape_vec(
[results.len() / max_width, max_width],
results,
)?)
}
Just thinking about it, if you want to take a variant type then you can always drop down to xladd's raw interface.
That's where I originally started but with null values and conversions, my code got really messy (lots of it/else statements) which is why I wrote the xladd-derive macro.
On my todo list is Optional arguments represented by Option
Thanks for clarification,
Yes - i can drop down - but I'd have to write the wrapper to handle the results (not much work admitedly) - I just though that a Variant as input would also be reasonable (since it's safe . the non strongly typed part is protected) - but thats fine - your crate your call :-)
As for options, always nice but would not help me now - i need json input to send so was planning to effectively write a add-in function that takes two columns of "field names" in col1 and "values" in col2 that i then merge to a json string to return / send (the values in the json struct needs to be serialized diffrently depending on if they are numbers or strings or bools etc.)
However - your string workarkound should work very well - a bit unecissary to go float - string - float but not a problem for this case.
thanks
Add it as a feature request - I'm always open to adding things.
Another argumenr for this (or alternatve) in the high level api is to be able to acess the shape of the input - eg implementing matrix multiplication of two ranges.
Yeah, so I've done all the matrix ops in xl8ml which might save you a lot of time. After some design thought it was easier to use ndarrays. If it's allowable, what is the project you are working on?
Fair point on ndarray! Its an internal project im affraid so im nit allowed to share details :-( (But no not doing matrix operations it was just a easy example)
Discussion complete
Hi Again,
Sorry to keep bothering you - am I correct in uderstanding that the derive function (which provide nice Result<> wrapping!) does not support any input type that holds a variable typed input array / matrix?
I.e. if i in Excel do =my_test(A1:B8)
In the underlying crate I could then define a function that would give me a single LPXLOPER12 / Variant in where i Could iterate over each matrix element and do different things depending on if they contain strings or numbers e.g. (but then without the error wrapping)
I naively tried to derive such a function using:
Without any luck