Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A couple things:</p> <p>1- I find out that your .rs file cannot have the same name as your .java file</p> <p>2- you declared a output variable on your root function (*v_out) but never compute it inside the function.</p> <p>3- Your java arrays are all ints. From the power function declaration on the <a href="http://developer.android.com/reference/renderscript/rs__cl_8rsh.html#a9243de1d67fcc847a89f95748d664b19" rel="nofollow">Renderscript API</a>, they all take at least a float as input</p> <p>Here is my java code:</p> <pre><code> public class Sum extends Activity { private float[] input; private float[] output; private RenderScript mRS; private Allocation mInAllocation; private Allocation mOutAllocation; private TextView t1; private ScriptC_Square mScript; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sum); t1= new TextView(this); t1= (TextView)findViewById(R.id.textview1); input= new float[4]; input[0]=0; input[1]=1; input[2]=2; input[3]=3; output =new float[input.length]; createScript(); } private void createScript() { mRS = RenderScript.create(this); mInAllocation = Allocation.createSized(mRS, Element.F32(mRS),4); mOutAllocation = Allocation.createTyped(mRS,mInAllocation.getType()); mScript = new ScriptC_Square(mRS, getResources(), R.raw.square); mInAllocation.copyFrom(input); mScript.forEach_root(mInAllocation, mOutAllocation); // calls the forEach function to operate on the root function (each allocation input, will have a corresponding allocation output mOutAllocation.copyTo(output); // copy the result that was stored in mOutAllocation into the array output t1.setText(String.format("Input:%s\n\noutput:%s", ArrayToString(input), ArrayToString(output))); } /** * this function just print each element of a primitive float array into a text string * @param array * @return */ public String ArrayToString(float[] array){ String s=""; for(int i=0; i&lt;array.length; i++){ s+= String.format("\nValue %d: %f", i, array[i]); } return s; } } </code></pre> <p>Here is my Square.rs file:</p> <pre><code>#pragma version(1) #pragma rs java_package_name(com.example.sum)//don't forget to change that package name void root(const float *v_in, float *v_out ){ *v_out = pow(*v_in, 2); //use the internal pow function of Renderscript pow(float x, float y) = x ^y; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload