Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Port the provided Fortran code into VB while preserving the original functionality. | Program Cholesky_decomp
implicit none
INTEGER, PARAMETER :: m=3
INTEGER, PARAMETER :: n=3
COMPLEX, DIMENSION(m,n) :: A
REAL, DIMENSION(m,n) :: L
REAL :: sum1, sum2
INTEGER i,j,k
A(1,:)=(/ 25, 15, -5 /)
A(2,:)=(/ 15, 18, 0 /)
A(3,:)=(/ -5, 0, 11 /)
L(1,1)=real(sqrt(A(1,1)))
L(2,1)=... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Translate this program into C but keep the logic exactly as in Groovy. | def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Convert the following code from Groovy to C#, ensuring the logic remains intact. | def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Port the following code from Groovy to C++ with equivalent syntax and logic. | def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Maintain the same structure and functionality when rewriting this code in Java. | def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Translate this program into Python but keep the logic exactly as in Groovy. | def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Ensure the translated VB code behaves exactly like the original Groovy snippet. | def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Write the same code in Go as shown below in Groovy. | def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Produce a functionally identical C code for the snippet given in Haskell. | module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Maintain the same structure and functionality when rewriting this code in C#. | module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Convert the following code from Haskell to C++, ensuring the logic remains intact. | module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Can you help me rewrite this code in Java instead of Haskell, keeping it the same logically? | module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Translate the given Haskell code snippet into Python without altering its behavior. | module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Write the same code in VB as shown below in Haskell. | module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Produce a language-to-language conversion: from Haskell to Go, same semantics. | module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Keep all operations the same but rewrite the snippet in C. | procedure cholesky (array)
result := make_square_array (*array)
every (i := 1 to *array) do {
every (k := 1 to i) do {
sum := 0
every (j := 1 to (k-1)) do {
sum +:= result[i][j] * result[k][j]
}
if (i = k)
then result[i][k] := sqrt(array[i][i] - sum)
else result... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Convert the following code from Icon to C#, ensuring the logic remains intact. | procedure cholesky (array)
result := make_square_array (*array)
every (i := 1 to *array) do {
every (k := 1 to i) do {
sum := 0
every (j := 1 to (k-1)) do {
sum +:= result[i][j] * result[k][j]
}
if (i = k)
then result[i][k] := sqrt(array[i][i] - sum)
else result... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Convert this Icon snippet to C++ and keep its semantics consistent. | procedure cholesky (array)
result := make_square_array (*array)
every (i := 1 to *array) do {
every (k := 1 to i) do {
sum := 0
every (j := 1 to (k-1)) do {
sum +:= result[i][j] * result[k][j]
}
if (i = k)
then result[i][k] := sqrt(array[i][i] - sum)
else result... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Port the following code from Icon to Java with equivalent syntax and logic. | procedure cholesky (array)
result := make_square_array (*array)
every (i := 1 to *array) do {
every (k := 1 to i) do {
sum := 0
every (j := 1 to (k-1)) do {
sum +:= result[i][j] * result[k][j]
}
if (i = k)
then result[i][k] := sqrt(array[i][i] - sum)
else result... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Change the following Icon code into Python without altering its purpose. | procedure cholesky (array)
result := make_square_array (*array)
every (i := 1 to *array) do {
every (k := 1 to i) do {
sum := 0
every (j := 1 to (k-1)) do {
sum +:= result[i][j] * result[k][j]
}
if (i = k)
then result[i][k] := sqrt(array[i][i] - sum)
else result... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Write the same algorithm in VB as shown in this Icon implementation. | procedure cholesky (array)
result := make_square_array (*array)
every (i := 1 to *array) do {
every (k := 1 to i) do {
sum := 0
every (j := 1 to (k-1)) do {
sum +:= result[i][j] * result[k][j]
}
if (i = k)
then result[i][k] := sqrt(array[i][i] - sum)
else result... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Convert this Icon block to Go, preserving its control flow and logic. | procedure cholesky (array)
result := make_square_array (*array)
every (i := 1 to *array) do {
every (k := 1 to i) do {
sum := 0
every (j := 1 to (k-1)) do {
sum +:= result[i][j] * result[k][j]
}
if (i = k)
then result[i][k] := sqrt(array[i][i] - sum)
else result... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Keep all operations the same but rewrite the snippet in C. | mp=: +/ . *
h =: +@|:
cholesky=: 3 : 0
n=. #A=. y
if. 1>:n do.
assert. (A=|A)>0=A
%:A
else.
'X Y t Z'=. , (;~n$(>.-:n){.1) <;.1 A
L0=. cholesky X
L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
L0,(T mp L0),.L1
end.
)
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Translate this program into C# but keep the logic exactly as in J. | mp=: +/ . *
h =: +@|:
cholesky=: 3 : 0
n=. #A=. y
if. 1>:n do.
assert. (A=|A)>0=A
%:A
else.
'X Y t Z'=. , (;~n$(>.-:n){.1) <;.1 A
L0=. cholesky X
L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
L0,(T mp L0),.L1
end.
)
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Please provide an equivalent version of this J code in C++. | mp=: +/ . *
h =: +@|:
cholesky=: 3 : 0
n=. #A=. y
if. 1>:n do.
assert. (A=|A)>0=A
%:A
else.
'X Y t Z'=. , (;~n$(>.-:n){.1) <;.1 A
L0=. cholesky X
L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
L0,(T mp L0),.L1
end.
)
| #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Translate the given J code snippet into Java without altering its behavior. | mp=: +/ . *
h =: +@|:
cholesky=: 3 : 0
n=. #A=. y
if. 1>:n do.
assert. (A=|A)>0=A
%:A
else.
'X Y t Z'=. , (;~n$(>.-:n){.1) <;.1 A
L0=. cholesky X
L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
L0,(T mp L0),.L1
end.
)
| import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Rewrite this program in Python while keeping its functionality equivalent to the J version. | mp=: +/ . *
h =: +@|:
cholesky=: 3 : 0
n=. #A=. y
if. 1>:n do.
assert. (A=|A)>0=A
%:A
else.
'X Y t Z'=. , (;~n$(>.-:n){.1) <;.1 A
L0=. cholesky X
L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
L0,(T mp L0),.L1
end.
)
| from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Transform the following J implementation into VB, maintaining the same output and logic. | mp=: +/ . *
h =: +@|:
cholesky=: 3 : 0
n=. #A=. y
if. 1>:n do.
assert. (A=|A)>0=A
%:A
else.
'X Y t Z'=. , (;~n$(>.-:n){.1) <;.1 A
L0=. cholesky X
L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
L0,(T mp L0),.L1
end.
)
| Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Convert this J block to Go, preserving its control flow and logic. | mp=: +/ . *
h =: +@|:
cholesky=: 3 : 0
n=. #A=. y
if. 1>:n do.
assert. (A=|A)>0=A
%:A
else.
'X Y t Z'=. , (;~n$(>.-:n){.1) <;.1 A
L0=. cholesky X
L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
L0,(T mp L0),.L1
end.
)
| package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Transform the following Julia implementation into C, maintaining the same output and logic. | a = [25 15 5; 15 18 0; -5 0 11]
b = [18 22 54 22; 22 70 86 62; 54 86 174 134; 42 62 134 106]
println(a, "\n => \n", chol(a, :L))
println(b, "\n => \n", chol(b, :L))
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Rewrite this program in C# while keeping its functionality equivalent to the Julia version. | a = [25 15 5; 15 18 0; -5 0 11]
b = [18 22 54 22; 22 70 86 62; 54 86 174 134; 42 62 134 106]
println(a, "\n => \n", chol(a, :L))
println(b, "\n => \n", chol(b, :L))
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Change the programming language of this snippet from Julia to C++ without modifying what it does. | a = [25 15 5; 15 18 0; -5 0 11]
b = [18 22 54 22; 22 70 86 62; 54 86 174 134; 42 62 134 106]
println(a, "\n => \n", chol(a, :L))
println(b, "\n => \n", chol(b, :L))
| #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Port the provided Julia code into Java while preserving the original functionality. | a = [25 15 5; 15 18 0; -5 0 11]
b = [18 22 54 22; 22 70 86 62; 54 86 174 134; 42 62 134 106]
println(a, "\n => \n", chol(a, :L))
println(b, "\n => \n", chol(b, :L))
| import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Produce a functionally identical Python code for the snippet given in Julia. | a = [25 15 5; 15 18 0; -5 0 11]
b = [18 22 54 22; 22 70 86 62; 54 86 174 134; 42 62 134 106]
println(a, "\n => \n", chol(a, :L))
println(b, "\n => \n", chol(b, :L))
| from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Write a version of this Julia function in VB with identical behavior. | a = [25 15 5; 15 18 0; -5 0 11]
b = [18 22 54 22; 22 70 86 62; 54 86 174 134; 42 62 134 106]
println(a, "\n => \n", chol(a, :L))
println(b, "\n => \n", chol(b, :L))
| Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Can you help me rewrite this code in Go instead of Julia, keeping it the same logically? | a = [25 15 5; 15 18 0; -5 0 11]
b = [18 22 54 22; 22 70 86 62; 54 86 174 134; 42 62 134 106]
println(a, "\n => \n", chol(a, :L))
println(b, "\n => \n", chol(b, :L))
| package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Translate this program into C but keep the logic exactly as in Mathematica. | CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Please provide an equivalent version of this Mathematica code in C#. | CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Ensure the translated C++ code behaves exactly like the original Mathematica snippet. | CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
| #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Rewrite this program in Java while keeping its functionality equivalent to the Mathematica version. | CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
| import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Convert this Mathematica snippet to Python and keep its semantics consistent. | CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
| from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Transform the following Mathematica implementation into VB, maintaining the same output and logic. | CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
| Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Maintain the same structure and functionality when rewriting this code in Go. | CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
| package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Convert this MATLAB snippet to C and keep its semantics consistent. | A = [
25 15 -5
15 18 0
-5 0 11 ];
B = [
18 22 54 42
22 70 86 62
54 86 174 134
42 62 134 106 ];
[L] = chol(A,'lower')
[L] = chol(B,'lower')
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Please provide an equivalent version of this MATLAB code in C#. | A = [
25 15 -5
15 18 0
-5 0 11 ];
B = [
18 22 54 42
22 70 86 62
54 86 174 134
42 62 134 106 ];
[L] = chol(A,'lower')
[L] = chol(B,'lower')
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Change the programming language of this snippet from MATLAB to C++ without modifying what it does. | A = [
25 15 -5
15 18 0
-5 0 11 ];
B = [
18 22 54 42
22 70 86 62
54 86 174 134
42 62 134 106 ];
[L] = chol(A,'lower')
[L] = chol(B,'lower')
| #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Convert this MATLAB block to Java, preserving its control flow and logic. | A = [
25 15 -5
15 18 0
-5 0 11 ];
B = [
18 22 54 42
22 70 86 62
54 86 174 134
42 62 134 106 ];
[L] = chol(A,'lower')
[L] = chol(B,'lower')
| import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Generate a Python translation of this MATLAB snippet without changing its computational steps. | A = [
25 15 -5
15 18 0
-5 0 11 ];
B = [
18 22 54 42
22 70 86 62
54 86 174 134
42 62 134 106 ];
[L] = chol(A,'lower')
[L] = chol(B,'lower')
| from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Write the same code in VB as shown below in MATLAB. | A = [
25 15 -5
15 18 0
-5 0 11 ];
B = [
18 22 54 42
22 70 86 62
54 86 174 134
42 62 134 106 ];
[L] = chol(A,'lower')
[L] = chol(B,'lower')
| Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Please provide an equivalent version of this MATLAB code in Go. | A = [
25 15 -5
15 18 0
-5 0 11 ];
B = [
18 22 54 42
22 70 86 62
54 86 174 134
42 62 134 106 ];
[L] = chol(A,'lower')
[L] = chol(B,'lower')
| package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Convert this Nim block to C, preserving its control flow and logic. | import math, strutils, strformat
type Matrix[N: static int, T: SomeFloat] = array[N, array[N, T]]
proc cholesky[Matrix](a: Matrix): Matrix =
for i in 0 ..< a[0].len:
for j in 0 .. i:
var s = 0.0
for k in 0 ..< j:
s += result[i][k] * result[j][k]
result[i][j] = if i == j: sqrt(a[i][i]-s... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Produce a functionally identical C# code for the snippet given in Nim. | import math, strutils, strformat
type Matrix[N: static int, T: SomeFloat] = array[N, array[N, T]]
proc cholesky[Matrix](a: Matrix): Matrix =
for i in 0 ..< a[0].len:
for j in 0 .. i:
var s = 0.0
for k in 0 ..< j:
s += result[i][k] * result[j][k]
result[i][j] = if i == j: sqrt(a[i][i]-s... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Please provide an equivalent version of this Nim code in C++. | import math, strutils, strformat
type Matrix[N: static int, T: SomeFloat] = array[N, array[N, T]]
proc cholesky[Matrix](a: Matrix): Matrix =
for i in 0 ..< a[0].len:
for j in 0 .. i:
var s = 0.0
for k in 0 ..< j:
s += result[i][k] * result[j][k]
result[i][j] = if i == j: sqrt(a[i][i]-s... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Keep all operations the same but rewrite the snippet in Java. | import math, strutils, strformat
type Matrix[N: static int, T: SomeFloat] = array[N, array[N, T]]
proc cholesky[Matrix](a: Matrix): Matrix =
for i in 0 ..< a[0].len:
for j in 0 .. i:
var s = 0.0
for k in 0 ..< j:
s += result[i][k] * result[j][k]
result[i][j] = if i == j: sqrt(a[i][i]-s... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Convert this Nim block to Python, preserving its control flow and logic. | import math, strutils, strformat
type Matrix[N: static int, T: SomeFloat] = array[N, array[N, T]]
proc cholesky[Matrix](a: Matrix): Matrix =
for i in 0 ..< a[0].len:
for j in 0 .. i:
var s = 0.0
for k in 0 ..< j:
s += result[i][k] * result[j][k]
result[i][j] = if i == j: sqrt(a[i][i]-s... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Write the same code in VB as shown below in Nim. | import math, strutils, strformat
type Matrix[N: static int, T: SomeFloat] = array[N, array[N, T]]
proc cholesky[Matrix](a: Matrix): Matrix =
for i in 0 ..< a[0].len:
for j in 0 .. i:
var s = 0.0
for k in 0 ..< j:
s += result[i][k] * result[j][k]
result[i][j] = if i == j: sqrt(a[i][i]-s... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Keep all operations the same but rewrite the snippet in Go. | import math, strutils, strformat
type Matrix[N: static int, T: SomeFloat] = array[N, array[N, T]]
proc cholesky[Matrix](a: Matrix): Matrix =
for i in 0 ..< a[0].len:
for j in 0 .. i:
var s = 0.0
for k in 0 ..< j:
s += result[i][k] * result[j][k]
result[i][j] = if i == j: sqrt(a[i][i]-s... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Ensure the translated C code behaves exactly like the original OCaml snippet. | let cholesky inp =
let n = Array.length inp in
let res = Array.make_matrix n n 0.0 in
let factor i k =
let rec sum j =
if j = k then 0.0 else
res.(i).(j) *. res.(k).(j) +. sum (j+1) in
inp.(i).(k) -. sum 0 in
for col = 0 to n-1 do
res.(col).(col) <- sqrt (factor col col);... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Convert this OCaml snippet to C# and keep its semantics consistent. | let cholesky inp =
let n = Array.length inp in
let res = Array.make_matrix n n 0.0 in
let factor i k =
let rec sum j =
if j = k then 0.0 else
res.(i).(j) *. res.(k).(j) +. sum (j+1) in
inp.(i).(k) -. sum 0 in
for col = 0 to n-1 do
res.(col).(col) <- sqrt (factor col col);... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Convert this OCaml snippet to C++ and keep its semantics consistent. | let cholesky inp =
let n = Array.length inp in
let res = Array.make_matrix n n 0.0 in
let factor i k =
let rec sum j =
if j = k then 0.0 else
res.(i).(j) *. res.(k).(j) +. sum (j+1) in
inp.(i).(k) -. sum 0 in
for col = 0 to n-1 do
res.(col).(col) <- sqrt (factor col col);... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Write the same code in Java as shown below in OCaml. | let cholesky inp =
let n = Array.length inp in
let res = Array.make_matrix n n 0.0 in
let factor i k =
let rec sum j =
if j = k then 0.0 else
res.(i).(j) *. res.(k).(j) +. sum (j+1) in
inp.(i).(k) -. sum 0 in
for col = 0 to n-1 do
res.(col).(col) <- sqrt (factor col col);... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Transform the following OCaml implementation into Python, maintaining the same output and logic. | let cholesky inp =
let n = Array.length inp in
let res = Array.make_matrix n n 0.0 in
let factor i k =
let rec sum j =
if j = k then 0.0 else
res.(i).(j) *. res.(k).(j) +. sum (j+1) in
inp.(i).(k) -. sum 0 in
for col = 0 to n-1 do
res.(col).(col) <- sqrt (factor col col);... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Translate the given OCaml code snippet into VB without altering its behavior. | let cholesky inp =
let n = Array.length inp in
let res = Array.make_matrix n n 0.0 in
let factor i k =
let rec sum j =
if j = k then 0.0 else
res.(i).(j) *. res.(k).(j) +. sum (j+1) in
inp.(i).(k) -. sum 0 in
for col = 0 to n-1 do
res.(col).(col) <- sqrt (factor col col);... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Write a version of this OCaml function in Go with identical behavior. | let cholesky inp =
let n = Array.length inp in
let res = Array.make_matrix n n 0.0 in
let factor i k =
let rec sum j =
if j = k then 0.0 else
res.(i).(j) *. res.(k).(j) +. sum (j+1) in
inp.(i).(k) -. sum 0 in
for col = 0 to n-1 do
res.(col).(col) <- sqrt (factor col col);... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Convert this Pascal block to C, preserving its control flow and logic. | program CholeskyApp;
type
D2Array = array of array of double;
function cholesky(const A: D2Array): D2Array;
var
i, j, k: integer;
s: double;
begin
setlength(Result, length(A), length(A));
for i := low(Result) to high(Result) do
for j := 0 to i do
begin
s := 0;
for k := 0 to j - 1 do
... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Write a version of this Pascal function in C# with identical behavior. | program CholeskyApp;
type
D2Array = array of array of double;
function cholesky(const A: D2Array): D2Array;
var
i, j, k: integer;
s: double;
begin
setlength(Result, length(A), length(A));
for i := low(Result) to high(Result) do
for j := 0 to i do
begin
s := 0;
for k := 0 to j - 1 do
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Rewrite the snippet below in C++ so it works the same as the original Pascal code. | program CholeskyApp;
type
D2Array = array of array of double;
function cholesky(const A: D2Array): D2Array;
var
i, j, k: integer;
s: double;
begin
setlength(Result, length(A), length(A));
for i := low(Result) to high(Result) do
for j := 0 to i do
begin
s := 0;
for k := 0 to j - 1 do
... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Please provide an equivalent version of this Pascal code in Java. | program CholeskyApp;
type
D2Array = array of array of double;
function cholesky(const A: D2Array): D2Array;
var
i, j, k: integer;
s: double;
begin
setlength(Result, length(A), length(A));
for i := low(Result) to high(Result) do
for j := 0 to i do
begin
s := 0;
for k := 0 to j - 1 do
... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Generate an equivalent Python version of this Pascal code. | program CholeskyApp;
type
D2Array = array of array of double;
function cholesky(const A: D2Array): D2Array;
var
i, j, k: integer;
s: double;
begin
setlength(Result, length(A), length(A));
for i := low(Result) to high(Result) do
for j := 0 to i do
begin
s := 0;
for k := 0 to j - 1 do
... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Write the same code in VB as shown below in Pascal. | program CholeskyApp;
type
D2Array = array of array of double;
function cholesky(const A: D2Array): D2Array;
var
i, j, k: integer;
s: double;
begin
setlength(Result, length(A), length(A));
for i := low(Result) to high(Result) do
for j := 0 to i do
begin
s := 0;
for k := 0 to j - 1 do
... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Convert this Pascal block to Go, preserving its control flow and logic. | program CholeskyApp;
type
D2Array = array of array of double;
function cholesky(const A: D2Array): D2Array;
var
i, j, k: integer;
s: double;
begin
setlength(Result, length(A), length(A));
for i := low(Result) to high(Result) do
for j := 0 to i do
begin
s := 0;
for k := 0 to j - 1 do
... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Write the same algorithm in C as shown in this Perl implementation. | sub cholesky {
my $matrix = shift;
my $chol = [ map { [(0) x @$matrix ] } @$matrix ];
for my $row (0..@$matrix-1) {
for my $col (0..$row) {
my $x = $$matrix[$row][$col];
$x -= $$chol[$row][$_]*$$chol[$col][$_] for 0..$col;
$$chol[$row][$col] = $row == $col ? sqrt $x : $x/$$chol[$col][... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Write a version of this Perl function in C# with identical behavior. | sub cholesky {
my $matrix = shift;
my $chol = [ map { [(0) x @$matrix ] } @$matrix ];
for my $row (0..@$matrix-1) {
for my $col (0..$row) {
my $x = $$matrix[$row][$col];
$x -= $$chol[$row][$_]*$$chol[$col][$_] for 0..$col;
$$chol[$row][$col] = $row == $col ? sqrt $x : $x/$$chol[$col][... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Change the following Perl code into C++ without altering its purpose. | sub cholesky {
my $matrix = shift;
my $chol = [ map { [(0) x @$matrix ] } @$matrix ];
for my $row (0..@$matrix-1) {
for my $col (0..$row) {
my $x = $$matrix[$row][$col];
$x -= $$chol[$row][$_]*$$chol[$col][$_] for 0..$col;
$$chol[$row][$col] = $row == $col ? sqrt $x : $x/$$chol[$col][... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Convert this Perl block to Java, preserving its control flow and logic. | sub cholesky {
my $matrix = shift;
my $chol = [ map { [(0) x @$matrix ] } @$matrix ];
for my $row (0..@$matrix-1) {
for my $col (0..$row) {
my $x = $$matrix[$row][$col];
$x -= $$chol[$row][$_]*$$chol[$col][$_] for 0..$col;
$$chol[$row][$col] = $row == $col ? sqrt $x : $x/$$chol[$col][... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Can you help me rewrite this code in Python instead of Perl, keeping it the same logically? | sub cholesky {
my $matrix = shift;
my $chol = [ map { [(0) x @$matrix ] } @$matrix ];
for my $row (0..@$matrix-1) {
for my $col (0..$row) {
my $x = $$matrix[$row][$col];
$x -= $$chol[$row][$_]*$$chol[$col][$_] for 0..$col;
$$chol[$row][$col] = $row == $col ? sqrt $x : $x/$$chol[$col][... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Produce a language-to-language conversion: from Perl to VB, same semantics. | sub cholesky {
my $matrix = shift;
my $chol = [ map { [(0) x @$matrix ] } @$matrix ];
for my $row (0..@$matrix-1) {
for my $col (0..$row) {
my $x = $$matrix[$row][$col];
$x -= $$chol[$row][$_]*$$chol[$col][$_] for 0..$col;
$$chol[$row][$col] = $row == $col ? sqrt $x : $x/$$chol[$col][... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Please provide an equivalent version of this Perl code in Go. | sub cholesky {
my $matrix = shift;
my $chol = [ map { [(0) x @$matrix ] } @$matrix ];
for my $row (0..@$matrix-1) {
for my $col (0..$row) {
my $x = $$matrix[$row][$col];
$x -= $$chol[$row][$_]*$$chol[$col][$_] for 0..$col;
$$chol[$row][$col] = $row == $col ? sqrt $x : $x/$$chol[$col][... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Translate this program into C but keep the logic exactly as in PowerShell. | function cholesky ($a) {
$l = @()
if ($a) {
$n = $a.count
$end = $n - 1
$l = 1..$n | foreach {$row = @(0) * $n; ,$row}
foreach ($k in 0..$end) {
$m = $k - 1
$sum = 0
if(0 -lt $k) {
foreach ($j in 0..$m) {$sum += $l[$k][$j]*$l[$k... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Rewrite the snippet below in C# so it works the same as the original PowerShell code. | function cholesky ($a) {
$l = @()
if ($a) {
$n = $a.count
$end = $n - 1
$l = 1..$n | foreach {$row = @(0) * $n; ,$row}
foreach ($k in 0..$end) {
$m = $k - 1
$sum = 0
if(0 -lt $k) {
foreach ($j in 0..$m) {$sum += $l[$k][$j]*$l[$k... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Generate an equivalent C++ version of this PowerShell code. | function cholesky ($a) {
$l = @()
if ($a) {
$n = $a.count
$end = $n - 1
$l = 1..$n | foreach {$row = @(0) * $n; ,$row}
foreach ($k in 0..$end) {
$m = $k - 1
$sum = 0
if(0 -lt $k) {
foreach ($j in 0..$m) {$sum += $l[$k][$j]*$l[$k... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Change the following PowerShell code into Java without altering its purpose. | function cholesky ($a) {
$l = @()
if ($a) {
$n = $a.count
$end = $n - 1
$l = 1..$n | foreach {$row = @(0) * $n; ,$row}
foreach ($k in 0..$end) {
$m = $k - 1
$sum = 0
if(0 -lt $k) {
foreach ($j in 0..$m) {$sum += $l[$k][$j]*$l[$k... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Translate the given PowerShell code snippet into Python without altering its behavior. | function cholesky ($a) {
$l = @()
if ($a) {
$n = $a.count
$end = $n - 1
$l = 1..$n | foreach {$row = @(0) * $n; ,$row}
foreach ($k in 0..$end) {
$m = $k - 1
$sum = 0
if(0 -lt $k) {
foreach ($j in 0..$m) {$sum += $l[$k][$j]*$l[$k... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Convert this PowerShell snippet to VB and keep its semantics consistent. | function cholesky ($a) {
$l = @()
if ($a) {
$n = $a.count
$end = $n - 1
$l = 1..$n | foreach {$row = @(0) * $n; ,$row}
foreach ($k in 0..$end) {
$m = $k - 1
$sum = 0
if(0 -lt $k) {
foreach ($j in 0..$m) {$sum += $l[$k][$j]*$l[$k... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Transform the following PowerShell implementation into Go, maintaining the same output and logic. | function cholesky ($a) {
$l = @()
if ($a) {
$n = $a.count
$end = $n - 1
$l = 1..$n | foreach {$row = @(0) * $n; ,$row}
foreach ($k in 0..$end) {
$m = $k - 1
$sum = 0
if(0 -lt $k) {
foreach ($j in 0..$m) {$sum += $l[$k][$j]*$l[$k... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Produce a language-to-language conversion: from R to C, same semantics. | t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4)))
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Please provide an equivalent version of this R code in C#. | t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4)))
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Port the following code from R to C++ with equivalent syntax and logic. | t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4)))
| #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Generate an equivalent Java version of this R code. | t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4)))
| import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Convert the following code from R to Python, ensuring the logic remains intact. | t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4)))
| from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Port the following code from R to VB with equivalent syntax and logic. | t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4)))
| Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Port the following code from R to Go with equivalent syntax and logic. | t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4)))
| package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Write the same code in C as shown below in Racket. | #lang racket
(require math)
(define (cholesky A)
(define mref matrix-ref)
(define n (matrix-num-rows A))
(define L (for/vector ([_ n]) (for/vector ([_ n]) 0)))
(define (set L i j x) (vector-set! (vector-ref L i) j x))
(define (ref L i j) (vector-ref (vector-ref L i) j))
(for* ([i n] [k n])
(set L i k
... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Convert this Racket block to C#, preserving its control flow and logic. | #lang racket
(require math)
(define (cholesky A)
(define mref matrix-ref)
(define n (matrix-num-rows A))
(define L (for/vector ([_ n]) (for/vector ([_ n]) 0)))
(define (set L i j x) (vector-set! (vector-ref L i) j x))
(define (ref L i j) (vector-ref (vector-ref L i) j))
(for* ([i n] [k n])
(set L i k
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cholesky
{
class Program
{
static void Main(string[] args)
{
double[,] test1 = new double[,]
{
{25, 15, -5},
... |
Can you help me rewrite this code in C++ instead of Racket, keeping it the same logically? | #lang racket
(require math)
(define (cholesky A)
(define mref matrix-ref)
(define n (matrix-num-rows A))
(define L (for/vector ([_ n]) (for/vector ([_ n]) 0)))
(define (set L i j x) (vector-set! (vector-ref L i) j x))
(define (ref L i j) (vector-ref (vector-ref L i) j))
(for* ([i n] [k n])
(set L i k
... | #include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns, scalar_type value)
... |
Produce a functionally identical Java code for the snippet given in Racket. | #lang racket
(require math)
(define (cholesky A)
(define mref matrix-ref)
(define n (matrix-num-rows A))
(define L (for/vector ([_ n]) (for/vector ([_ n]) 0)))
(define (set L i j x) (vector-set! (vector-ref L i) j x))
(define (ref L i j) (vector-ref (vector-ref L i) j))
(for* ([i n] [k n])
(set L i k
... | import java.util.Arrays;
public class Cholesky {
public static double[][] chol(double[][] a){
int m = a.length;
double[][] l = new double[m][m];
for(int i = 0; i< m;i++){
for(int k = 0; k < (i+1); k++){
double sum = 0;
for(int j = 0; j < k; j++){
sum += l[i][j] * l[k][j];
}
l[i][k] = (i... |
Preserve the algorithm and functionality while converting the code from Racket to Python. | #lang racket
(require math)
(define (cholesky A)
(define mref matrix-ref)
(define n (matrix-num-rows A))
(define L (for/vector ([_ n]) (for/vector ([_ n]) 0)))
(define (set L i j x) (vector-set! (vector-ref L i) j x))
(define (ref L i j) (vector-ref (vector-ref L i) j))
(for* ([i n] [k n])
(set L i k
... | from __future__ import print_function
from pprint import pprint
from math import sqrt
def cholesky(A):
L = [[0.0] * len(A) for _ in xrange(len(A))]
for i in xrange(len(A)):
for j in xrange(i+1):
s = sum(L[i][k] * L[j][k] for k in xrange(j))
L[i][j] = sqrt(A[i][i] - s) if (i ==... |
Rewrite the snippet below in VB so it works the same as the original Racket code. | #lang racket
(require math)
(define (cholesky A)
(define mref matrix-ref)
(define n (matrix-num-rows A))
(define L (for/vector ([_ n]) (for/vector ([_ n]) 0)))
(define (set L i j x) (vector-set! (vector-ref L i) j x))
(define (ref L i j) (vector-ref (vector-ref L i) j))
(for* ([i n] [k n])
(set L i k
... | Function Cholesky(Mat As Range) As Variant
Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte
If Mat.Rows.Count <> Mat.Columns.Count Then
MsgBox ("Correlation matrix is not square")
Exit Function
End If
m = Mat.Rows.Count
... |
Change the following Racket code into Go without altering its purpose. | #lang racket
(require math)
(define (cholesky A)
(define mref matrix-ref)
(define n (matrix-num-rows A))
(define L (for/vector ([_ n]) (for/vector ([_ n]) 0)))
(define (set L i j x) (vector-set! (vector-ref L i) j x))
(define (ref L i j) (vector-ref (vector-ref L i) j))
(for* ([i n] [k n])
(set L i k
... | package main
import (
"fmt"
"math"
)
type symmetric struct {
order int
ele []float64
}
type lower struct {
order int
ele []float64
}
func (s *symmetric) print() {
const eleFmt = "%10.5f "
row, diag := 1, 0
for i, e := range s.ele {
fmt.Printf(eleFmt, e)
i... |
Please provide an equivalent version of this REXX code in C. |
niner = '25 15 -5' ,
'15 18 0' ,
'-5 0 11'
call Cholesky niner
hexer = 18 22 54 42,
22 70 86 62,
54 86 174 134,
42 62 134 106
call Cholesky hex... | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.