Code Monkey home page Code Monkey logo

Comments (7)

tr8dr avatar tr8dr commented on June 26, 2024

The code does not handle this currently. If you are handy with low level reflection code, could add code to scan for fields and consider these to be properties more or less.

Perhaps easier would be to expose some of these constants as properties, in which case the bridge will see these.

In R would get the property as:

obj$Get("CONST_1")

In python:

obj.CONST_1

from .net-bridge.

PavelBal avatar PavelBal commented on June 26, 2024

@tr8dr Thank you for the reply! I will try the second option.

from .net-bridge.

PavelBal avatar PavelBal commented on June 26, 2024

Could you also give me a hint how to create a .NET array of a certain type in R?

I tried
myArray= .cstatic("System.Array", "CreateInstance", myType, 0);

but I'm getting

Error in internal_ccall_static(classname, methodname, argv) : 
  closing connection 

from .net-bridge.

tr8dr avatar tr8dr commented on June 26, 2024

If the target array is one of the types recognized: int, double, float, string. You can just create the vector on the R side and then pass to a function.

For example if you have a function that takes a double[]:

class Foo {
     public double Sum(double[] vector) {
        ...
     }
     public double SumVector(DenseVector<double> vector) {
        ...
     }
}

You can call this function directly with an R vector.

obj <- .cnew("Foo")
v <- rnorm(100)
obj$Sum (v)

Or if you use MathNet.Numerics, can use functions with signatures for matrices and vectors:

obj <- .cnew("Foo")
v <- rnorm(100)
obj$SumVector (v)

If you are trying to create a type that is not something R would understand, not sure why you would bother to create from R. If you provide more context in terms of what you want to do can suggest a solution.

from .net-bridge.

PavelBal avatar PavelBal commented on June 26, 2024

I need to call a function that requires an array of a custom type as one of the arguments:

public ParameterValue[] CreateIndividual(OriginData matlabOriginData, IEnumerable<MoleculeOntogeny> moleculeOntogenies){
I can create an object of type OriginData from within R, and the output type 'ParameterValue' offers getter/setter for retrieving numerical and string data.

So far I'm trying to figure out how much I can do without writing a wrapper in C#.

from .net-bridge.

tr8dr avatar tr8dr commented on June 26, 2024

You should be able to see the ParameterValue[] objects. I suspect where it is confused is with the IEnumerable<...>.

I think the problem with the array you were creating above is that the array would initially be empty. R can view and index into an array of objects, but in creating the array initially does not have objects in it (unless it is a struct type). The Bridge will attempt to return a R list of these objects, but then the array cells are uninitialized, presenting a problem.

Even if you created the array and the R bridge was OK with uninitialized cells, there is no functionality to set a value in the array. I'd have to check, but you might be able to create a R list of objects and then this will be converted in the call.

If we are considering an array of MoleculeOntogeny objects, could do as follows:

ontogeny <- list()
ontogeny[[1]] <- .cnew ("...")
ontogeny[[2]] <- .cnew("...")

obj$CreateIndividual (..., ontogeny)

if you call your function, this will be presented as a List<> of these objects.

from .net-bridge.

PavelBal avatar PavelBal commented on June 26, 2024

Great, thank you, I'll give it a try!

from .net-bridge.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.